#include <DLException.h>
Public Member Functions | |
DLException () | |
DLException (const DLException &orig) | |
const DLException & | operator= (const DLException &right) |
DLException (DLExceptionCodes errCode, const char *str, const char *filename=0, const int lineNum=0) | |
string | dlGetErrorMsg () const |
DLExceptionCodes | dlGetErrorID () const |
const char * | what () const throw () |
virtual | ~DLException () throw () |
Protected Attributes | |
string | errorMessage |
Error message. | |
DLExceptionCodes | errorID |
Exception ID. |
DLException is a DOCLIB user-defined exception message object that will be thrown when an error has been detected in the DOCLIB library. The DLException contains the error message and an ID (from the enum DLExceptionCodes) that describes the reason of the exception.
DOCLIB programmers who are creating libraries for others' use should report errors by throwing a DLException, or a class derived from DLException.
Programmers using the DOCLIB API should expect that an exception may be thrown when invoking DOCLIB functionality; for example, opening an image file into a DLImage should be placed inside a try
block, since if, for instance, the desired image file does not exist, the DLImage::dlLoadImage() code will throw a DLException.
Note: Need to free any dynamically-allocated memory not handled by a destructor before throwing an exception.
Typical usage:
#include <exception> #include "DLException.h" try { callSomeFunction(); } // Catch DLException referance catch(const DLException &ex) { // Get the error message // and print to screen cout << ex.what(); // Get the exception ID. DLExceptionCodes errorID = ex.dlGetErrorID(); } // Catch any exception derived from the standard C++ exception catch(const std::exception &ex) { // Get the error message // and print to screen cout << ex.what(); } // Catch all unknown excpetions catch (...) { cout << "unknown exception!!"; } : : : void callSomeFunction() { // Test some condition. If condition is not right, // Throw a DLException if( something wrong ) // Clean up memory { // __FILE__ is a macro that will insert the current file name // __LINE__ is a macro that will insert the current line number throw DLException(DL_IO_EXCEPTION, "Cannot find input file", __FILE__, __LINE__); } }
Definition at line 110 of file DLException.h.
DLException::DLException | ( | ) |
Default DLException Constructor
DLException::DLException | ( | const DLException & | orig | ) |
Copy Constructor for copying the DLException
DLException::DLException | ( | DLExceptionCodes | errCode, | |
const char * | str, | |||
const char * | filename = 0 , |
|||
const int | lineNum = 0 | |||
) |
DLException Constructor that takes in the error code, error message, filename and line number.
errCode | exception code; can be one of the following:
| |
str | error message string | |
filename | Source code file name where the exception is being thrown. This is an optional field. Should use __FILE__ (a macro for the current file name). | |
lineNum | Line number where the exception is being thrown. This is an optional field. Should use __LINE__ (a macro for the line number of the throw statement) |
virtual DLException::~DLException | ( | ) | throw () [virtual] |
Default Destructor
const DLException& DLException::operator= | ( | const DLException & | right | ) |
Assignment operator
right | DLException to be copied |
string DLException::dlGetErrorMsg | ( | ) | const |
DLExceptionCodes DLException::dlGetErrorID | ( | ) | const |
Gets the error ID
const char* DLException::what | ( | ) | const throw () |
An inherited function from std::exception.
string DLException::errorMessage [protected] |
DLExceptionCodes DLException::errorID [protected] |