# cexception.h

    00001 //==========================================================================
    00002 //  CEXCEPTION.H - part of
    00003 //                     OMNeT++/OMNEST
    00004 //            Discrete System Simulation in C++
    00005 //
    00006 //
    00007 //  Exception class
    00008 //
    00009 //==========================================================================
    00010
    00011 /*--------------------------------------------------------------*
    00012   Copyright (C) 1992-2005 Andras Varga
    00013
    00014   This file is distributed WITHOUT ANY WARRANTY. See the file
    00015   `license' for details on this and other legal matters.
    00016 *--------------------------------------------------------------*/
    00017
    00018 #ifndef __CEXCEPTION_H
    00019 #define __CEXCEPTION_H
    00020
    00021 #include <stdarg.h>  // for va_list
    00022 #include "defs.h"
    00023 #include "opp_string.h"
    00024
    00025 class cObject;
    00026 class cModule;
    00027
    00033 class SIM_API cException
    00034 {
    00035   protected:
    00036     int errorcode;
    00037     opp_string msg;
    00038     opp_string moduleclassname;
    00039     opp_string modulefullpath;
    00040     int moduleid;
    00041
    00047     void init(const cObject *obj, int errc, const char *fmt, va_list va);
    00048
    00049     // helper for init()
    00050     void storeCtx();
    00051
    00052   public:
    00058     cException();
    00059
    00065     cException(int errcode,...);
    00066
    00070     cException(const char *msg,...);
    00071
    00079     cException(const cObject *where, int errcode,...);
    00080
    00086     cException(const cObject *where, const char *msg,...);
    00087
    00091     virtual ~cException() {}
    00093
    00096
    00100     int errorCode() {return errorcode;}
    00101
    00105     const char *message() {return msg.c_str();}
    00106
    00111     const char *moduleClassName() {return moduleclassname.c_str();}
    00112
    00117     const char *moduleFullPath() {return modulefullpath.c_str();}
    00118
    00125     int moduleID() {return moduleid;}
    00127 };
    00128
    00137 class SIM_API cTerminationException : public cException
    00138 {
    00139   public:
    00145     cTerminationException(int errcode,...);
    00146
    00150     cTerminationException(const char *msg,...);
    00151 };
    00152
    00161 class SIM_API cRuntimeError : public cException
    00162 {
    00163   protected:
    00164     // internal
    00165     void breakIntoDebuggerIfRequested();
    00166
    00167   public:
    00173     cRuntimeError(int errcode,...);
    00174
    00178     cRuntimeError(const char *msg,...);
    00179
    00187     cRuntimeError(const cObject *where, int errcode,...);
    00188
    00194     cRuntimeError(const cObject *where, const char *msg,...);
    00195 };
    00196
    00204 class SIM_API cEndModuleException : public cException
    00205 {
    00206   private:
    00207     bool del; // if true, currently running module should be deleted
    00208
    00209   public:
    00213     cEndModuleException(bool moduleToBeDeleted=false) {del = moduleToBeDeleted;}
    00214
    00218     bool moduleToBeDeleted() {return del;}
    00219 };
    00220
    00229 class SIM_API cStackCleanupException : public cException
    00230 {
    00231   public:
    00235     cStackCleanupException();
    00236 };
    00237
    00238 #endif