Public Member Functions | Protected Attributes | List of all members
cSDHLibraryException Class Reference

Base class for exceptions in the SDHLibrary-CPP. More...

#include <sdhexception.h>

Inheritance diagram for cSDHLibraryException:
Inheritance graph
[legend]

Public Member Functions

 cSDHLibraryException (char const *_type, cMsg const &_msg)
 
virtual const char * what () const throw ()
 

Protected Attributes

cMsg msg
 The message object. More...
 

Detailed Description

Base class for exceptions in the SDHLibrary-CPP.

At construction time a cMsg object is stored in the msg member of the cSDHLibraryException object. The cMsg object should contain a string wich further describes the actual cause of the exception thrown. The string in the cMsg object can be queried with the overloaded what() member function, just like in the std::exception class.

See the verbose description of the constructor #SDH::cSDHLibraryException::cSDHLibraryException() for examplary use.

Definition at line 132 of file sdhexception.h.

Constructor & Destructor Documentation

◆ cSDHLibraryException()

NAMESPACE_SDH_END cSDHLibraryException::cSDHLibraryException ( char const *  _type,
cMsg const &  _msg 
)

Constructor of sdh exception base class.

Parameters
_type- the type name of the exception. By convention this is the class name of the exception
_msg- a reference to a cMsg object that further describes the exception.
Remarks
  • The _type parameter is mainly usefull in derived classes
  • The _msg given as parameter is copied to the msg member. Thus the given _msg object can be an anonymous object, like in:
...
if ( v > v_max )
throw new cSDHLibraryException( "cSDHLibraryException", cMsg( "Failed since v is invalid (v=%d > %d=v_max)", v, v_max ) );
  • But exceptions of the base will hardly ever be thrown. Instead objects of derived, more specific classes will be thrown. This looks like:
    // Derived exception class for more specific exceptions:
    class VCC_EXPORT cDerivedException : public cSDHLibraryException
    {
    public:
    cDerivedException( cMsg const & _msg )
    : cSDHLibraryException( "cDerivedException", _msg )
    {}
    }
    // (Yes that is really all that must be done here!)
    ...
    try
    {
    ...
    if ( v > v_max )
    throw new cDerivedException( cMsg( "Failed since v is invalid (v=%d > %d=v_max)", v, v_max ) );
    ...
    }
    catch ( cDerivedException *e )
    {
    cerr << "Caught exception " << e->what() << "\n";
    // handle exception
    ...
    // finally delete the caught exception
    delete e;
    }

Definition at line 106 of file sdhexception.cpp.

Member Function Documentation

◆ what()

const char * cSDHLibraryException::what ( ) const
throw (
)
virtual

Return the msg member

Definition at line 118 of file sdhexception.cpp.

Member Data Documentation

◆ msg

cMsg cSDHLibraryException::msg
protected

The message object.

Definition at line 137 of file sdhexception.h.


The documentation for this class was generated from the following files:
cSDHLibraryException
Base class for exceptions in the SDHLibrary-CPP.
Definition: sdhexception.h:132
cSDHLibraryException::cSDHLibraryException
cSDHLibraryException(char const *_type, cMsg const &_msg)
Definition: sdhexception.cpp:106
cMsg
Class for short, fixed maximum length text messages.
Definition: sdhexception.h:77


sdhlibrary_cpp
Author(s): Dirk Osswald
autogenerated on Wed Mar 2 2022 01:00:59