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;
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) {
142 DLLLOCAL
void getLocation(QoreExceptionLocation& loc)
const {
143 if (isBuiltin() && callStack) {
147 assert(v.getType() ==
NT_HASH);
151 if (*str !=
"<builtin>") {
152 loc.file = str->
c_str();
153 kv = v.get<
const QoreHashNode>()->getKeyValue(
"source");
162 loc.start_line = kv.getAsBigInt();
163 kv = v.get<
const QoreHashNode>()->getKeyValue(
"endline");
164 loc.end_line = kv.getAsBigInt();
165 kv = v.get<
const QoreHashNode>()->getKeyValue(
"offset");
166 loc.offset = kv.getAsBigInt();
177 DLLLOCAL QoreException* rethrow();
180 DLLLOCAL ~QoreException() {
189 DLLLOCAL
static const char* getType(qore_call_t type);
194 DLLLOCAL QoreException& operator=(
const QoreException&) =
delete;
197 class ParseException :
public QoreException {
200 DLLLOCAL ParseException(
const QoreProgramLocation& loc,
const char* err,
QoreStringNode* desc) : QoreException(loc, err, desc) {
204 hashdecl qore_es_private {
205 bool thread_exit =
false;
206 QoreException* head =
nullptr, * tail =
nullptr;
208 DLLLOCAL qore_es_private() {
211 DLLLOCAL ~qore_es_private() {
214 DLLLOCAL
void clearIntern() {
219 head = tail =
nullptr;
223 DLLLOCAL
void insert(QoreException *e) {
232 DLLLOCAL
void appendListIntern(
QoreString& str)
const {
233 QoreException* w = head;
239 if (!w->file.empty())
240 str.
sprintf(
"%s:", w->file.c_str());
242 str.
sprintf(
"%d", w->start_line);
243 if (w->end_line && w->end_line != w->start_line)
244 str.
sprintf(
"-%d", w->end_line);
247 str.
sprintf(
"%s: %s", err->getBuffer(), desc->getBuffer());
256 DLLLOCAL
void addStackInfo(qore_call_t type,
const char *class_name,
const char *code,
257 const QoreProgramLocation& loc);
264 QoreException* w = head;
274 for (
auto& i : stack)
278 DLLLOCAL
static void addStackInfo(
ExceptionSink& xsink, qore_call_t type,
const char* class_name,
279 const char* code,
const QoreProgramLocation& loc) {
280 xsink.priv->addStackInfo(type, class_name, code, loc);
284 xsink.priv->appendListIntern(str);
288 class ParseExceptionSink {
293 DLLLOCAL ~ParseExceptionSink();
DLLEXPORT const char * c_str() const
returns the string's buffer; this data should not be changed
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
const qore_type_t NT_HASH
type value for QoreHashNode
Definition: node_types.h:51
The main value class in Qore, designed to be passed by value.
Definition: QoreValue.h:262
const qore_type_t NT_STRING
type value for QoreStringNode
Definition: node_types.h:45
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
For use on the stack only: iterates through elements of a const QoreListNode.
Definition: QoreListNode.h:566