Qore Programming Language  0.8.3
include/qore/ExceptionSink.h (4311)
00001 /* -*- mode: c++; indent-tabs-mode: nil -*- */
00002 /*
00003   ExceptionSink.h
00004 
00005   Qore Programming Language ExceptionSink class definition
00006 
00007   Copyright 2003 - 2011 David Nichols
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 */
00023 
00024 #ifndef _QORE_EXCEPTIONSINK_H
00025 
00026 #define _QORE_EXCEPTIONSINK_H
00027 
00028 #include <stdarg.h>
00029 #include <stdio.h>
00030 
00031 class QoreException;
00032 class QoreProgramLocation;
00033 
00035 class ExceptionSink {
00036 private:
00038    struct qore_es_private *priv;
00039 
00041    DLLLOCAL ExceptionSink(const ExceptionSink&);
00042 
00044    DLLLOCAL ExceptionSink& operator=(const ExceptionSink&);
00045       
00046 public:
00048    DLLEXPORT ExceptionSink();
00049 
00051    DLLEXPORT ~ExceptionSink();
00052 
00054    DLLEXPORT void handleExceptions();
00055 
00057    DLLEXPORT void handleWarnings();
00058 
00060    DLLEXPORT bool isEvent() const;
00061 
00063    DLLEXPORT bool isThreadExit() const;
00064 
00066    DLLEXPORT bool isException() const;
00067 
00069 
00075    DLLEXPORT operator bool () const;
00076 
00078 
00083    DLLEXPORT AbstractQoreNode *raiseException(const char *err, const char *fmt, ...);
00084 
00086 
00092    DLLEXPORT AbstractQoreNode *raiseErrnoException(const char *err, int en, const char *fmt, ...);
00093 
00095 
00101    DLLEXPORT AbstractQoreNode *raiseExceptionArg(const char* err, AbstractQoreNode* arg, const char* fmt, ...);
00102 
00104 
00110    DLLEXPORT AbstractQoreNode *raiseExceptionArg(const char* err, AbstractQoreNode* arg, QoreStringNode *desc);
00111 
00113 
00118    DLLEXPORT AbstractQoreNode *raiseException(const char *err, QoreStringNode *desc);
00119 
00121    DLLEXPORT void raiseThreadExit();
00122 
00124    DLLEXPORT void assimilate(ExceptionSink *xs);
00125 
00127    DLLEXPORT void assimilate(ExceptionSink &xs);
00128 
00130    DLLEXPORT void outOfMemory();
00131 
00133    DLLEXPORT void clear();
00134 
00135    DLLLOCAL void raiseException(QoreException *e);
00136    DLLLOCAL void raiseException(const QoreListNode *n);
00137    DLLLOCAL void raiseException(const QoreProgramLocation &loc, const char *err, AbstractQoreNode *arg, AbstractQoreNode *desc);
00138    DLLLOCAL void raiseException(const QoreProgramLocation &loc, const char *err, AbstractQoreNode *arg, const char *fmt, ...);
00139    DLLLOCAL QoreException *catchException();
00140    DLLLOCAL void overrideLocation(int sline, int eline, const char *file);
00141    DLLLOCAL void rethrow(QoreException *old);
00142    DLLLOCAL void addStackInfo(int type, const char *class_name, const char *code, const char *file, int start_line, int end_line);
00143    DLLLOCAL void addStackInfo(int type, const char *class_name, const char *code);
00144 
00145    DLLLOCAL static void defaultExceptionHandler(QoreException *e);
00146    DLLLOCAL static void defaultWarningHandler(QoreException *e);
00147 };
00148 
00149 static inline void alreadyDeleted(ExceptionSink *xsink, const char *cmeth) {
00150    xsink->raiseException("OBJECT-ALREADY-DELETED", "the method %s() cannot be executed because the object has already been deleted", cmeth);
00151 }
00152 
00153 static inline void makeAccessDeletedObjectException(ExceptionSink *xsink, const char *mem, const char *cname) {
00154    xsink->raiseException("OBJECT-ALREADY-DELETED", "attempt to access member '%s' of an already-deleted object of class '%s'", mem, cname);
00155 }
00156 
00157 static inline void makeAccessDeletedObjectException(ExceptionSink *xsink, const char *cname) {
00158    xsink->raiseException("OBJECT-ALREADY-DELETED", "attempt to access an already-deleted object of class '%s'", cname);
00159 }
00160 
00161 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines