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(
const QoreProgramLocation& loc) : QoreProgramLineLocation(loc),
65 file(loc.getFileValue()), source(loc.getSourceValue()), lang(loc.getLanguageValue()), offset(loc.offset) {
68 DLLLOCAL QoreExceptionLocation(
const QoreExceptionLocation& old) : QoreProgramLineLocation(old),
69 file(old.file), source(old.source), lang(old.lang), offset(old.offset) {
72 DLLLOCAL QoreExceptionLocation(QoreExceptionLocation&& old) =
default;
74 DLLLOCAL
void set(
const QoreProgramLocation& loc) {
75 start_line = loc.start_line;
76 end_line = loc.end_line;
77 file = loc.getFileValue();
78 source = loc.getSourceValue();
79 lang = loc.getLanguageValue();
84 class QoreException :
public QoreExceptionBase,
public QoreExceptionLocation {
86 friend hashdecl qore_es_private;
89 QoreException* next =
nullptr;
98 QoreExceptionLocation(*get_runtime_location()) {
102 : QoreExceptionBase(n_err, n_desc, n_arg),
103 QoreExceptionLocation(*get_runtime_location()) {
106 DLLLOCAL QoreException(
const QoreException& old) : QoreExceptionBase(old),
107 QoreExceptionLocation(old), next(old.next ? new QoreException(*old.next) : nullptr) {
111 DLLLOCAL QoreException(
const QoreListNode* n) : QoreExceptionBase(0, 0, 0, CT_USER),
112 QoreExceptionLocation(*get_runtime_location()) {
120 DLLLOCAL QoreException(
const QoreProgramLocation& n_loc,
const char *n_err,
QoreValue n_desc,
122 QoreExceptionBase(new
QoreStringNode(n_err), n_desc, n_arg, n_type), QoreExceptionLocation(n_loc) {
127 DLLLOCAL QoreException* rethrow();
130 DLLLOCAL ~QoreException() {
139 DLLLOCAL
static const char* getType(qore_call_t type);
144 DLLLOCAL QoreException& operator=(
const QoreException&) =
delete;
147 class ParseException :
public QoreException {
150 DLLLOCAL ParseException(
const QoreProgramLocation& loc,
const char* err,
QoreStringNode* desc) : QoreException(loc, err, desc) {
154 hashdecl qore_es_private {
155 bool thread_exit =
false;
156 QoreException* head =
nullptr, * tail =
nullptr;
158 DLLLOCAL qore_es_private() {
161 DLLLOCAL ~qore_es_private() {
164 DLLLOCAL
void clearIntern() {
169 head = tail =
nullptr;
173 DLLLOCAL
void insert(QoreException *e) {
182 DLLLOCAL
void appendListIntern(
QoreString& str)
const {
183 QoreException* w = head;
189 if (!w->file.empty())
190 str.
sprintf(
"%s:", w->file.c_str());
192 str.
sprintf(
"%d", w->start_line);
193 if (w->end_line && w->end_line != w->start_line)
194 str.
sprintf(
"-%d", w->end_line);
197 str.
sprintf(
"%s: %s", err->getBuffer(), desc->getBuffer());
206 DLLLOCAL
void addStackInfo(qore_call_t type,
const char *class_name,
const char *code,
207 const QoreProgramLocation& loc);
214 QoreException* w = head;
224 for (
auto& i : stack)
228 DLLLOCAL
static void addStackInfo(
ExceptionSink& xsink, qore_call_t type,
const char* class_name,
229 const char* code,
const QoreProgramLocation& loc) {
230 xsink.priv->addStackInfo(type, class_name, code, loc);
234 xsink.priv->appendListIntern(str);
238 class ParseExceptionSink {
243 DLLLOCAL ~ParseExceptionSink();
DLLEXPORT QoreValue getReferencedEntry(size_t index) const
returns the element at "index" (first element is index 0), the caller owns the reference ...
This is the hash or associative list container type in Qore, dynamically allocated only...
Definition: QoreHashNode.h:50
DLLEXPORT int sprintf(const char *fmt,...)
this will concatentate a formatted string to the existing string according to the format string and t...
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:81
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50
DLLEXPORT void concat(const QoreString *str, ExceptionSink *xsink)
concatenates a string and converts encodings if necessary
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
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:46
DLLEXPORT void ref() const
increments the reference count
this class is used to safely manage calls to AbstractQoreNode::getStringRepresentation() when a QoreS...
Definition: QoreStringNode.h:401
DLLEXPORT QoreListNode * copyListFrom(size_t index) const
performs a deep copy of the list starting from element "offset" and returns the new list ...
Qore call stack.
Definition: ExceptionSink.h:310
DLLEXPORT bool hasNode() const
returns true if the object contains a non-null AbstractQoreNode pointer (ie type == QV_Node && v...
call stack element; strings must be in the default encoding for the Qore process
Definition: ExceptionSink.h:291