OMNeT++ Simulation Library  6.0.3
cException Class Reference

#include <cexception.h>

Description

Exception class.

Inheritance diagram for cException:
cDeleteModuleException cRuntimeError cStackCleanupException cTerminationException

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 cExceptiondup () const
 
virtual ~cException () throw ()
 
Updating the exception message
virtual void setMessage (const char *txt)
 
virtual void prependMessage (const char *txt)
 
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)
 

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".

◆ cException() [5/5]

cException ( const cException )
default

Copy constructor. We unfortunately need to copy exception objects when handing them back from an activity() method.

◆ ~cException()

virtual ~cException ( )
throw (
)
inlinevirtual

Destructor.

Member Function Documentation

◆ init()

void init ( const cObject obj,
ErrorCode  errorcode,
const std::string &  msg 
)
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: ..."

◆ dup()

virtual cException* dup ( ) const
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 cStackCleanupException, cDeleteModuleException, cRuntimeError, and cTerminationException.

◆ setMessage()

virtual void setMessage ( const char *  txt)
inlinevirtual

Overwrites the message text with the given one.

◆ prependMessage()

virtual void prependMessage ( const char *  txt)
inlinevirtual

Prefixes the message with the given text and a colon.

◆ isError()

virtual bool isError ( ) const
inlinevirtual

Whether the exception represents an error or a normal (non-error) terminating condition (e.g. "Simulation completed").

Reimplemented in cStackCleanupException, cDeleteModuleException, and cTerminationException.

◆ getErrorCode()

virtual int getErrorCode ( ) const
inlinevirtual

Returns the error code.

◆ what()

virtual const char* what ( ) const
throw (
)
inlineoverridevirtual

Returns the text of the error. Redefined from std::exception.

◆ getFormattedMessage()

virtual std::string getFormattedMessage ( ) const
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()

virtual int getSimulationStage ( ) const
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()

virtual eventnumber_t getEventNumber ( ) const
inlinevirtual

Returns the event number at the creation of the exception object.

◆ getSimtime()

virtual simtime_t getSimtime ( ) const
inlinevirtual

Returns the simulation time at the creation of the exception object.

◆ hasContext()

virtual bool hasContext ( ) const
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()

virtual const char* getContextClassName ( ) const
inlinevirtual

Returns the class name (NED type name) of the component in context when the exception occurred.

◆ getContextFullPath()

virtual const char* getContextFullPath ( ) const
inlinevirtual

Returns the full path of the component in context when the exception occurred.

◆ getContextComponentId()

virtual int getContextComponentId ( ) const
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()

virtual int getContextComponentKind ( ) const
inlinevirtual

Returns the kind of the component in context when the exception occurred. (The return value can be safely cast to cComponent::ComponentKind.)


The documentation for this class was generated from the following file: