Category: functors Component type: concept


ErrorHandler is a class that is called whenever errors are thrown or warnings are encountered inside DTL. This class is primarily useful if the user wants to trap any errors in DTL globally and/or do things like create a log of all internal errors thrown. (If you want to trap errors when reading or writing rows from a table see the IOHandler class). To use this class define an error handling function (or a functor if you want to log information in a class) with the signature

dtl_ios_base::MeansOfRecovery myHandler(const RootException *, ErrorSeverity::SeverityCode severity);

This function should return dtl_ios_base::THROW_EXCEPTION to have the exception thrown and dtl_ios_base::SUPPRESS_ERROR to suppress the error. (Be careful about suppressing errors, DTL uses internal throws to communicate errors between routines, if you suppress an error you may prevent a routine from operating correctly.) The global error handler may be set by calling


Where myHandler can be either a function pointer or a functor class. See the file RootException.h for more details on this class.


1. Create an error handling function which accepts a pointer to RootException and a severity code which indicates a warning (ErrorHandler::ERR_WARNING) or a fatal error (ErrorHandler::ERR_FAILURE). A typical example with a functor is (see example/GlobalHandler.cpp)


		GlobalHandlerExample::operator()(const RootException *pEx, ErrorSeverity::SeverityCode severity)


	switch (severity)


	    case ErrorSeverity::ERR_WARNING : 

			cout << "Warning encountered!  Handle your warnings here!" << endl;

			cout << "Suppressing error!" << endl;

			return dtl_ios_base::SUPPRESS_ERROR;


		case ErrorSeverity::ERR_FAILURE :

			cout << "Error encountered!  Handle your exceptions here!" << endl;

			cout << "Rethrowing exception!" << endl;

			return dtl_ios_base::THROW_EXCEPTION;


	cout << "Shouldn't get here!" << endl;

	return dtl_ios_base::THROW_EXCEPTION; // suppress return value warning for MSVC


2. In your application code, set the global error handler to be the error handler you just wrote:


See also


[DTL Home]

Copyright 2002, Michael Gradman and Corwin Joy.

Permission to use, copy, modify, distribute and sell this software and its documentation for any purpose is hereby granted without fee, provided that the above copyright notice appears in all copies and that both that copyright notice and this permission notice appear in supporting documentation. Corwin Joy and Michael Gradman make no representations about the suitability of this software for any purpose. It is provided "as is" without express or implied warranty.

SourceForge Logo

This site written using the ORB. [The ORB]