|
General IRI utilities
|
Generic exception. More...
#include <exceptions.h>


Public Member Functions | |
| CException (const std::string &where, const std::string &error_msg) | |
| Class constructor. More... | |
| virtual const std::string & | what (void) |
| Function to get the error message. More... | |
| virtual | ~CException () throw () |
| Class destructor. More... | |
Protected Attributes | |
| std::string | error_msg |
| Exception error message. More... | |
This class inherits from the std::exception class to provide generic exceptions for for all classes. The error message is provided at construction time with all the necessary information about the error that has generated the exception. When the exception is caught, the what() function may be used to get the error message.
This class should be used as a base class for all other exception classes in any program. This way it will be simple to distinguish between system exceptions and application exceptions.
When throwing exceptions, it is important to free all allocated resources and also to set all the class attributes and variables to a known state. Otherwise the behavior of the program after an exception is thrown could be unpredictible.
Next there is a scketch of a program to catch exceptions:
* try{
* user code here
* }catch(CException &e){
* handle the exception
* }
* There exist no copy constructor, so if it is necessary to rethrow an exception just use throw; instead of throw e;, because the later tries to create a new CException object and initialize it with the information of the original one.
This code will catch any exception of this class or any inherited class. Several catch statements can be used to catch exceptions of different classes separatelly and handle them in different ways.
Definition at line 76 of file exceptions.h.
| CException::CException | ( | const std::string & | where, |
| const std::string & | error_msg | ||
| ) |
The constructor of this class allocates the necessary memory to store the error message. In addition to the error message provided to the constructor, the name of the function, filename and line where the error has ocurred, as well as the text "[Exception caught] - " is pre-appended to label the message as an exception.
| where | a null terminated string with the information about the name of the function, the source code filename and the line where the exception was generated. This string must be generated by the HERE macro. |
| error_msg | a null terminated string that contains the error message. This string may have any valid character and there is no limit on its length. |
Definition at line 25 of file exceptions.cpp.
References error_msg.
|
virtual | |||||||||||||
This destructor just frees all the memory allocated to store the error message.
Definition at line 38 of file exceptions.cpp.
|
virtual |
This function is used to get the error message with the information about the error that has generated the exception.
Definition at line 33 of file exceptions.cpp.
References error_msg.
|
protected |
This attribute is a string which contains the error message with the information about the error that has generated the exception. This message is allocated and initialized at construction time and can not be modified afterwards.
When the exception is caught, the what() function must be used to get the contents of this error message.
Definition at line 90 of file exceptions.h.
Referenced by CEventException::CEventException(), CEventServerException::CEventServerException(), CEventTimeoutException::CEventTimeoutException(), CException(), CLogException::CLogException(), CMutexException::CMutexException(), CThreadException::CThreadException(), CThreadServerException::CThreadServerException(), CTimeException::CTimeException(), and what().
1.8.6