32 #ifndef _QORE_QOREEXCEPTION_H
34 #define _QORE_QOREEXCEPTION_H
39 hashdecl QoreExceptionBase {
45 qore_call_t n_type = CT_BUILTIN);
47 DLLLOCAL QoreExceptionBase(
const QoreExceptionBase& old) :
48 type(old.type), callStack(old.callStack->copy()),
49 err(old.err.refSelf()), desc(old.desc.refSelf()),
50 arg(old.arg.refSelf()) {
53 DLLLOCAL ~QoreExceptionBase() {
58 hashdecl QoreExceptionLocation : QoreProgramLineLocation {
64 DLLLOCAL QoreExceptionLocation() {
67 DLLLOCAL QoreExceptionLocation(
const QoreProgramLocation& loc) : QoreProgramLineLocation(loc),
68 file(loc.getFileValue()), source(loc.getSourceValue()), lang(loc.getLanguageValue()), offset(loc.offset) {
71 DLLLOCAL QoreExceptionLocation(
const QoreExceptionLocation& old) : QoreProgramLineLocation(old),
72 file(old.file), source(old.source), lang(old.lang), offset(old.offset) {
75 DLLLOCAL QoreExceptionLocation(QoreExceptionLocation&& old) =
default;
77 DLLLOCAL QoreExceptionLocation& operator=(
const QoreExceptionLocation& other) {
78 start_line = other.start_line;
79 end_line = other.end_line;
81 source = other.source;
83 offset = other.offset;
87 DLLLOCAL
void set(
const QoreProgramLocation& loc) {
88 start_line = loc.start_line;
89 end_line = loc.end_line;
90 file = loc.getFileValue();
91 source = loc.getSourceValue();
92 lang = loc.getLanguageValue();
96 DLLLOCAL
bool isBuiltin()
const {
97 return file ==
"<builtin>" && (start_line == end_line) && (start_line == -1);
101 class QoreException :
public QoreExceptionBase,
public QoreExceptionLocation {
103 friend hashdecl qore_es_private;
106 QoreException* next =
nullptr;
110 DLLLOCAL
QoreHashNode* makeExceptionObject(
int level = 0)
const;
115 QoreExceptionLocation(*get_runtime_location()) {
119 : QoreExceptionBase(n_err, n_desc, n_arg),
120 QoreExceptionLocation(*get_runtime_location()) {
123 DLLLOCAL QoreException(
const QoreException& old) : QoreExceptionBase(old),
124 QoreExceptionLocation(old), next(old.next ? new QoreException(*old.next) : nullptr) {
128 DLLLOCAL QoreException(
const QoreListNode* n) : QoreExceptionBase(0, 0, 0, CT_USER),
129 QoreExceptionLocation(*get_runtime_location()) {
137 DLLLOCAL QoreException(
const QoreProgramLocation& n_loc,
const char *n_err,
QoreValue n_desc,
139 QoreExceptionBase(new
QoreStringNode(n_err), n_desc, n_arg, n_type), QoreExceptionLocation(n_loc) {
150 DLLLOCAL
void getLocation(QoreExceptionLocation& loc)
const {
151 if (isBuiltin() && callStack) {
155 assert(v.getType() ==
NT_HASH);
159 if (*str !=
"<builtin>") {
160 loc.file = str->
c_str();
161 kv = v.get<
const QoreHashNode>()->getKeyValue(
"source");
170 loc.start_line = kv.getAsBigInt();
171 kv = v.get<
const QoreHashNode>()->getKeyValue(
"endline");
172 loc.end_line = kv.getAsBigInt();
173 kv = v.get<
const QoreHashNode>()->getKeyValue(
"offset");
174 loc.offset = kv.getAsBigInt();
185 DLLLOCAL QoreException* rethrow();
188 DLLLOCAL ~QoreException() {
197 DLLLOCAL
static const char* getType(qore_call_t type);
202 DLLLOCAL QoreException& operator=(
const QoreException&) =
delete;
205 class ParseException :
public QoreException {
208 DLLLOCAL ParseException(
const QoreProgramLocation& loc,
const char* err,
QoreStringNode* desc) : QoreException(loc, err, desc) {
212 hashdecl qore_es_private {
213 QoreException* head =
nullptr, * tail =
nullptr;
214 bool thread_exit =
false;
215 bool rethrown =
false;
217 DLLLOCAL qore_es_private() {
220 DLLLOCAL ~qore_es_private() {
223 DLLLOCAL
void clearIntern() {
228 head = tail =
nullptr;
232 DLLLOCAL
void insert(QoreException *e) {
241 DLLLOCAL
void appendListIntern(
QoreString& str)
const {
242 QoreException* w = head;
248 if (!w->file.empty())
249 str.
sprintf(
"%s:", w->file.c_str());
251 str.
sprintf(
"%d", w->start_line);
252 if (w->end_line && w->end_line != w->start_line)
253 str.
sprintf(
"-%d", w->end_line);
256 str.
sprintf(
"%s: %s", err->getBuffer(), desc->getBuffer());
265 DLLLOCAL
void addStackInfo(qore_call_t type,
const char *class_name,
const char *code,
266 const QoreProgramLocation& loc);
273 QoreException* w = head;
283 for (
auto& i : stack)
287 DLLLOCAL
void assimilate(qore_es_private& es);
289 DLLLOCAL
void rethrow(QoreException* old) {
290 insert(old->rethrow());
298 DLLLOCAL
static const qore_es_private* get(
const ExceptionSink& xsink) {
302 DLLLOCAL
static void addStackInfo(
ExceptionSink& xsink, qore_call_t type,
const char* class_name,
303 const char* code,
const QoreProgramLocation& loc) {
304 xsink.priv->addStackInfo(type, class_name, code, loc);
308 xsink.priv->appendListIntern(str);
312 class ParseExceptionSink {
317 DLLLOCAL ~ParseExceptionSink();
DLLEXPORT void ref() const
increments the reference count
For use on the stack only: iterates through elements of a const QoreListNode.
Definition: QoreListNode.h:563
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
DLLEXPORT size_t size() const
returns the number of elements in the list
DLLEXPORT QoreListNode * copyListFrom(size_t index) const
performs a deep copy of the list starting from element "offset" and returns the new list
DLLEXPORT QoreValue getReferencedEntry(size_t index) const
returns the element at "index" (first element is index 0), the caller owns the reference
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
DLLEXPORT void concat(const QoreString *str, ExceptionSink *xsink)
concatenates a string and converts encodings if necessary
DLLEXPORT int sprintf(const char *fmt,...)
this will concatentate a formatted string to the existing string according to the format string and t...
DLLEXPORT const char * c_str() const
returns the string's buffer; this data should not be changed
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
this class is used to safely manage calls to AbstractQoreNode::getStringRepresentation() when a QoreS...
Definition: QoreStringNode.h:378
const qore_type_t NT_STRING
type value for QoreStringNode
Definition: node_types.h:45
const qore_type_t NT_HASH
type value for QoreHashNode
Definition: node_types.h:51
call stack element; strings must be in the default encoding for the Qore process
Definition: ExceptionSink.h:306
Qore call stack.
Definition: ExceptionSink.h:325
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:275
DLLEXPORT bool hasNode() const
returns true if the object contains a non-null AbstractQoreNode pointer (ie type == QV_Node && v....