cException Class Reference¶
|
API
|
Public Member Functions | |
Constructors, destructor | |
| cException (ErrorCodeInt errcode,...) | |
| cException (const char *msg,...) | |
| cException (const cObject *where, ErrorCodeInt errcode,...) | |
| cException (const cObject *where, const char *msg,...) | |
| cException (const cException &)=default | |
| virtual cException * | dup () const |
| virtual | ~cException () throw () |
Updating the exception message | |
| virtual void | setMessage (const char *txt) |
| virtual void | prependMessage (const char *fmt,...) |
| virtual void | appendMessage (const char *fmt,...) |
Getting exception info | |
| virtual bool | isError () const |
| virtual int | getErrorCode () const |
| virtual const char * | what () const override throw () |
| virtual std::string | getFormattedMessage () const |
| virtual int | getSimulationStage () const |
| virtual eventnumber_t | getEventNumber () const |
| virtual simtime_t | getSimtime () const |
| virtual bool | hasContext () const |
| virtual const char * | getContextClassName () const |
| virtual const char * | getContextFullPath () const |
| virtual int | getContextComponentId () const |
| virtual int | getContextComponentKind () const |
Protected Member Functions | |
| void | init (const cObject *obj, ErrorCode errorcode, const std::string &msg) |
Description
Exception class.
Constructor & Destructor Documentation
◆ cException() [1/5]
| cException | ( | ErrorCodeInt | errcode, |
| ... ) |
Error is identified by an error code, and the message comes from a string table. The error string may expect printf-like arguments (s, d) which also have to be passed to the constructor.
◆ cException() [2/5]
| cException | ( | const char * | msg, |
| ... ) |
To be called like printf(). The error code is set to E_CUSTOM.
◆ cException() [3/5]
| cException | ( | const cObject * | where, |
| ErrorCodeInt | errcode, | ||
| ... ) |
Error is identified by an error code, and the message comes from a string table. The error string may expect printf-like arguments (s, d) which also have to be passed to the constructor. The 1st arg is the object where the error occurred: its class and object name will be prepended to the message like this: "(cArray)arr".
◆ cException() [4/5]
| cException | ( | const cObject * | where, |
| const char * | msg, | ||
| ... ) |
To be called like printf(). The error code is set to E_CUSTOM. The 1st arg is the object where the error occurred: its class and object name will be prepended to the message like this: "(cArray)arr".
References init().
◆ cException() [5/5]
|
default |
Copy constructor. We unfortunately need to copy exception objects when handing them back from an activity() method.
◆ ~cException()
|
inlinevirtual | ||||||||||||
Destructor.
Member Function Documentation
◆ init()
|
protected |
Helper function for constructors: assembles and stores the message text. If the first arg is non-nullptr, the message text will be prepended (if needed) with the object type and name, like this: "(cArray)array: ..."
Referenced by cException(), cRuntimeError::cRuntimeError(), and cTerminationException::cTerminationException().
◆ dup()
|
inlinevirtual |
Creates and returns an exact copy of this object. We unfortunately need to copy exception objects when handing them back from an activity() method.
Reimplemented in cDeleteModuleException, cRuntimeError, cStackCleanupException, and cTerminationException.
◆ setMessage()
|
inlinevirtual |
Overwrites the message text with the given one.
◆ prependMessage()
|
virtual |
Prefixes the message with the given printf-like formatted text.
References prependMessage().
Referenced by prependMessage().
◆ appendMessage()
|
virtual |
Appends the given printf-like formatted text to the message.
References appendMessage().
Referenced by appendMessage().
◆ isError()
|
inlinevirtual |
Whether the exception represents an error or a normal (non-error) terminating condition (e.g. "Simulation completed").
Reimplemented in cDeleteModuleException, cStackCleanupException, and cTerminationException.
References isError().
Referenced by isError().
◆ getErrorCode()
|
inlinevirtual |
Returns the error code.
◆ what()
|
inlineoverridevirtual | ||||||||||||
Returns the text of the error. Redefined from std::exception.
◆ getFormattedMessage()
|
virtual |
Returns a formatted message that includes the "Error" word, context information, the event number and simulation time if available and relevant, in addition to the exception message (what()).
◆ getSimulationStage()
|
inlinevirtual |
Returns in which stage of the simulation the exception object was created: during network building (CTX_BUILD), network initialization (CTX_INITIALIZE), simulation execution (CTX_EVENT), finalization (CTX_FINISH), or network cleanup (CTX_CLEANUP).
◆ getEventNumber()
|
inlinevirtual |
Returns the event number at the creation of the exception object.
◆ getSimtime()
|
inlinevirtual |
Returns the simulation time at the creation of the exception object.
◆ hasContext()
|
inlinevirtual |
Returns true if the exception has "context info", that is, it occurred within a known module or channel. getContextClassName(), getContextFullPath() and getContextComponentId() may only be called if this method returns true.
◆ getContextClassName()
|
inlinevirtual |
Returns the class name (NED type name) of the component in context when the exception occurred.
◆ getContextFullPath()
|
inlinevirtual |
Returns the full path of the component in context when the exception occurred.
◆ getContextComponentId()
|
inlinevirtual |
Returns the ID of the component in context when the exception occurred, or -1 if there was no component in context. The component may not exist any more when the exception is caught (ie. if the exception occurs during network setup, the network is cleaned up immediately).
◆ getContextComponentKind()
|
inlinevirtual |
Returns the kind of the component in context when the exception occurred. (The return value can be safely cast to cComponent::ComponentKind.)
Generated on for API by