cSDHLibraryException Class Reference

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

#include <sdhexception.h>

Inheritance diagram for cSDHLibraryException:
Inheritance graph
[legend]

List of all members.

Public Member Functions

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

Protected Attributes

cMsg msg
 The message object.

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::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 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;
          }
    

Member Function Documentation

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

Return the msg member


Member Data Documentation

The message object.

Definition at line 137 of file sdhexception.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


cob_sdh
Author(s): Florian Weisshardt
autogenerated on Fri Jan 11 10:03:56 2013