Qore Programming Language  0.8.11.1
ExceptionSink.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  ExceptionSink.h
4 
5  Qore Programming Language ExceptionSink class definition
6 
7  Copyright (C) 2003 - 2014 David Nichols
8 
9  Permission is hereby granted, free of charge, to any person obtaining a
10  copy of this software and associated documentation files (the "Software"),
11  to deal in the Software without restriction, including without limitation
12  the rights to use, copy, modify, merge, publish, distribute, sublicense,
13  and/or sell copies of the Software, and to permit persons to whom the
14  Software is furnished to do so, subject to the following conditions:
15 
16  The above copyright notice and this permission notice shall be included in
17  all copies or substantial portions of the Software.
18 
19  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  DEALINGS IN THE SOFTWARE.
26 
27  Note that the Qore library is released under a choice of three open-source
28  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
29  information.
30 */
31 
32 #ifndef _QORE_EXCEPTIONSINK_H
33 
34 #define _QORE_EXCEPTIONSINK_H
35 
36 #include <stdarg.h>
37 #include <stdio.h>
38 
39 class QoreException;
40 struct QoreProgramLocation;
41 
44  friend struct qore_es_private;
45 
46 private:
48  struct qore_es_private *priv;
49 
51  DLLLOCAL ExceptionSink(const ExceptionSink&);
52 
54  DLLLOCAL ExceptionSink& operator=(const ExceptionSink&);
55 
56 public:
58  DLLEXPORT ExceptionSink();
59 
61  DLLEXPORT ~ExceptionSink();
62 
64  DLLEXPORT void handleExceptions();
65 
67  DLLEXPORT void handleWarnings();
68 
70  DLLEXPORT bool isEvent() const;
71 
73  DLLEXPORT bool isThreadExit() const;
74 
76  DLLEXPORT bool isException() const;
77 
79 
85  DLLEXPORT operator bool () const;
86 
88 
93  DLLEXPORT AbstractQoreNode *raiseException(const char *err, const char *fmt, ...);
94 
96 
102  DLLEXPORT AbstractQoreNode* raiseErrnoException(const char *err, int en, const char *fmt, ...);
103 
105 
111  DLLEXPORT AbstractQoreNode* raiseErrnoException(const char *err, int en, QoreStringNode* desc);
112 
114 
120  DLLEXPORT AbstractQoreNode *raiseExceptionArg(const char* err, AbstractQoreNode* arg, const char* fmt, ...);
121 
123 
129  DLLEXPORT AbstractQoreNode *raiseExceptionArg(const char* err, AbstractQoreNode* arg, QoreStringNode *desc);
130 
132 
137  DLLEXPORT AbstractQoreNode *raiseException(const char *err, QoreStringNode *desc);
138 
140  DLLEXPORT void raiseThreadExit();
141 
143  DLLEXPORT void assimilate(ExceptionSink *xs);
144 
146  DLLEXPORT void assimilate(ExceptionSink &xs);
147 
149  DLLEXPORT void outOfMemory();
150 
152  DLLEXPORT void clear();
153 
154  DLLLOCAL void raiseException(QoreException* e);
155  DLLLOCAL void raiseException(const QoreListNode* n);
156  DLLLOCAL void raiseException(const QoreProgramLocation& loc, const char* err, AbstractQoreNode* arg, AbstractQoreNode* desc);
157  DLLLOCAL void raiseException(const QoreProgramLocation& loc, const char* err, AbstractQoreNode* arg, const char* fmt, ...);
158  DLLLOCAL QoreException* catchException();
159  DLLLOCAL void overrideLocation(const QoreProgramLocation& loc);
160  DLLLOCAL void rethrow(QoreException* old);
161 
162  DLLLOCAL static void defaultExceptionHandler(QoreException* e);
163  DLLLOCAL static void defaultWarningHandler(QoreException* e);
164 };
165 
166 static inline void alreadyDeleted(ExceptionSink *xsink, const char *cmeth) {
167  xsink->raiseException("OBJECT-ALREADY-DELETED", "the method %s() cannot be executed because the object has already been deleted", cmeth);
168 }
169 
170 static inline void makeAccessDeletedObjectException(ExceptionSink *xsink, const char *mem, const char *cname) {
171  xsink->raiseException("OBJECT-ALREADY-DELETED", "attempt to access member '%s' of an already-deleted object of class '%s'", mem, cname);
172 }
173 
174 static inline void makeAccessDeletedObjectException(ExceptionSink *xsink, const char *cname) {
175  xsink->raiseException("OBJECT-ALREADY-DELETED", "attempt to access an already-deleted object of class '%s'", cname);
176 }
177 
178 #endif
DLLEXPORT void handleWarnings()
calls ExceptionSink::defaultWarningHandler() on all exceptions still present in the object and then d...
DLLEXPORT void outOfMemory()
intended to be used to handle out of memory errors FIXME: not yet fully implemented ...
DLLEXPORT ~ExceptionSink()
calls ExceptionSink::defaultExceptionHandler() on all exceptions still present in the object and then...
DLLEXPORT void handleExceptions()
calls ExceptionSink::defaultExceptionHandler() on all exceptions still present in the object and then...
DLLEXPORT bool isEvent() const
returns true if at least one exception is present or thread_exit has been triggered ...
The base class for all value and parse types in Qore expression trees.
Definition: AbstractQoreNode.h:55
DLLEXPORT AbstractQoreNode * raiseException(const char *err, const char *fmt,...)
appends a Qore-language exception to the list
DLLEXPORT AbstractQoreNode * raiseErrnoException(const char *err, int en, const char *fmt,...)
appends a Qore-language exception to the list and appends the result of strerror(errno) to the descri...
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:48
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
DLLEXPORT bool isThreadExit() const
returns true if thread_exit has been triggered
DLLEXPORT AbstractQoreNode * raiseExceptionArg(const char *err, AbstractQoreNode *arg, const char *fmt,...)
appends a Qore-language exception to the list, and sets the 'arg' member (this object takes over the ...
DLLEXPORT void clear()
deletes the exception list immediately
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:43
DLLEXPORT void raiseThreadExit()
sets the "thread_exit" flag; will cause the current thread to terminate
DLLEXPORT ExceptionSink()
creates an empty ExceptionSink object
DLLEXPORT void assimilate(ExceptionSink *xs)
assimilates all entries of the "xs" argument by appending them to the internal list and deletes the "...
DLLEXPORT bool isException() const
returns true if at least one exception is present