DLException Class Reference

Error message object used to deliver error messages in DOCLIB. More...

#include <DLException.h>

List of all members.

Public Member Functions

 DLException ()
 DLException (const DLException &orig)
const DLExceptionoperator= (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.


Detailed Description

Error message object used to deliver error messages in DOCLIB.

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.


Constructor & Destructor Documentation

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.

Parameters:
errCode exception code; can be one of the following:
  • DL_IO_EXCEPTION
  • DL_FILE_NOT_FOUND_EXCEPTION
  • DL_NOT_IMPLEMENTED_EXCEPTION
  • DL_UNKNOWN_FILE_FORMAT_EXCEPTION
  • DL_NULL_POINTER_EXCEPTION
  • DL_UNKNOWN_OBJECT_EXCEPTION
  • DL_WRONG_FORMAT_EXCEPTION
  • DL_NOT_SUPPORTED_IMAGE_EXCEPTION
  • DL_OUT_IMAGE_BOUNDARY_EXCEPTION
  • DL_OUT_CHANNEL_NUMBER_EXCEPTION
  • DL_NOT_SUPPORTED_EXCEPTION
  • DL_UNKNOWN_TAG_EXCEPTION
  • DL_MEMORY_EXCEPTION
  • DL_PARAMETERS_EXCEPTION
  • DL_INVALID_PAGE_NUMBER
  • DL_DEPRECATED_EXCEPTION
  • DL_INDEX_OUT_OF_BOUND
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


Member Function Documentation

const DLException& DLException::operator= ( const DLException right  ) 

Assignment operator

Parameters:
right DLException to be copied

string DLException::dlGetErrorMsg (  )  const

Returns:
error message string

DLExceptionCodes DLException::dlGetErrorID (  )  const

Gets the error ID

Returns:
error ID code; one of the following:
  • DL_IO_EXCEPTION
  • DL_FILE_NOT_FOUND_EXCEPTION
  • DL_NOT_IMPLEMENTED_EXCEPTION
  • DL_UNKNOWN_FILE_FORMAT_EXCEPTION
  • DL_NULL_POINTER_EXCEPTION
  • DL_UNKNOWN_OBJECT_EXCEPTION
  • DL_WRONG_FORMAT_EXCEPTION
  • DL_NOT_SUPPORTED_IMAGE_EXCEPTION
  • DL_OUT_IMAGE_BOUNDARY_EXCEPTION
  • DL_OUT_CHANNEL_NUMBER_EXCEPTION
  • DL_NOT_SUPPORTED_EXCEPTION
  • DL_UNKNOWN_TAG_EXCEPTION
  • DL_MEMORY_EXCEPTION
  • DL_PARAMETERS_EXCEPTION
  • DL_INVALID_PAGE_NUMBER
  • DL_DEPRECATED_EXCEPTION
  • DL_INDEX_OUT_OF_BOUND

const char* DLException::what (  )  const throw ()

An inherited function from std::exception.

Returns:
error message as C-style string


Member Data Documentation

string DLException::errorMessage [protected]

Error message.

Definition at line 205 of file DLException.h.

DLExceptionCodes DLException::errorID [protected]

Exception ID.

Definition at line 207 of file DLException.h.


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

DOCLIB is being developed under contract by a collaboration between:
The Laboratory for Language and Media Processing
Unviersity of Maryland, College Park
and
Booz | Allen | Hamilton

All Rights Reserved, 2003-2007