cexception.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __CEXCEPTION_H
00020 #define __CEXCEPTION_H
00021
00022 #include <stdarg.h>
00023 #include <exception>
00024 #include <stdexcept>
00025 #include "simkerneldefs.h"
00026 #include "simtime_t.h"
00027 #include "errmsg.h"
00028 #include "opp_string.h"
00029
00030 NAMESPACE_BEGIN
00031
00032 class cObject;
00033 class cComponent;
00034
00040 class SIM_API cException : public std::exception
00041 {
00042 protected:
00043 int errorcode;
00044 std::string msg;
00045
00046 int simulationstage;
00047 eventnumber_t eventnumber;
00048 simtime_t simtime;
00049
00050 bool hascontext;
00051 std::string contextclassname;
00052 std::string contextfullpath;
00053 int moduleid;
00054
00060 void init(const cObject *obj, OppErrorCode errorcode, const char *fmt, va_list va);
00061
00062
00063 void storeCtx();
00064
00065
00066 cException();
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077 void exitIfStartupError();
00078
00079 public:
00087 cException(OppErrorCode errcode,...);
00088
00092 cException(const char *msg,...);
00093
00101 cException(const cObject *where, OppErrorCode errcode,...);
00102
00108 cException(const cObject *where, const char *msg,...);
00109
00114 cException(const cException&);
00115
00120 virtual cException *dup() const {return new cException(*this);}
00121
00125 virtual ~cException() throw() {}
00127
00133 virtual void setMessage(const char *txt) {msg = txt;}
00134
00138 virtual void prependMessage(const char *txt) {msg = std::string(txt) + ": " + msg;}
00140
00147 virtual bool isError() const {return true;}
00148
00152 virtual int getErrorCode() const {return errorcode;}
00153
00157 virtual const char *what() const throw() {return msg.c_str();}
00158
00164 virtual std::string getFormattedMessage() const;
00165
00172 virtual int getSimulationStage() const {return simulationstage;}
00173
00177 virtual eventnumber_t getEventNumber() const {return eventnumber;}
00178
00182 virtual simtime_t getSimtime() const {return simtime;}
00183
00189 virtual bool hasContext() const {return hascontext;}
00190
00195 virtual const char *getContextClassName() const {return contextclassname.c_str();}
00196
00201 virtual const char *getContextFullPath() const {return contextfullpath.c_str();}
00202
00209 virtual int getModuleID() const {return moduleid;}
00211 };
00212
00221 class SIM_API cTerminationException : public cException
00222 {
00223 public:
00229 cTerminationException(OppErrorCode errcode,...);
00230
00234 cTerminationException(const char *msg,...);
00235
00240 cTerminationException(const cTerminationException& e) : cException(e) {}
00241
00246 virtual cTerminationException *dup() const {return new cTerminationException(*this);}
00247
00252 virtual bool isError() const {return false;}
00253 };
00254
00263 class SIM_API cRuntimeError : public cException
00264 {
00265 protected:
00266
00267 void breakIntoDebuggerIfRequested();
00268
00269 public:
00275 cRuntimeError(OppErrorCode errcode,...);
00276
00280 cRuntimeError(const char *msg,...);
00281
00289 cRuntimeError(const cObject *where, OppErrorCode errcode,...);
00290
00296 cRuntimeError(const cObject *where, const char *msg,...);
00297
00302 cRuntimeError(const cRuntimeError& e) : cException(e) {}
00303
00308 virtual cRuntimeError *dup() const {return new cRuntimeError(*this);}
00309 };
00310
00318 class SIM_API cDeleteModuleException : public cException
00319 {
00320 public:
00324 cDeleteModuleException() : cException() {}
00325
00330 cDeleteModuleException(const cDeleteModuleException& e) : cException(e) {}
00331
00336 virtual cDeleteModuleException *dup() const {return new cDeleteModuleException(*this);}
00337
00341 virtual bool isError() const {return false;}
00342 };
00343
00352 class SIM_API cStackCleanupException : public cException
00353 {
00354 public:
00358 cStackCleanupException() : cException() {}
00359
00364 cStackCleanupException(const cStackCleanupException& e) : cException(e) {}
00365
00370 virtual cStackCleanupException *dup() const {return new cStackCleanupException(*this);}
00371
00375 virtual bool isError() const {return false;}
00376 };
00377
00378 NAMESPACE_END
00379
00380
00381 #endif
00382
00383