CARMA C++
ErrorException.h File Reference

Exception class for errors. More...

#include <string>
#include <iosfwd>
#include <log4cpp/Priority.hh>
#include "carma/util/BaseException.h"

Go to the source code of this file.

Classes

class  carma::util::ErrorException
 Exception class for errors The exception comes with a text string that can be printed or logged. More...
 

Namespaces

module  carma
 IDL for bima Rx Control, inherits from antenna::common::RxControl.
 
 carma::util
 Utility classes.
 

Macros

#define CARMA_ASSERT(assertion)
 
#define CARMA_ERROR(y)
 Trick to get the file name and line number passed to the exception handler. More...
 
#define MAKE_DERIVED_ERROR_EXCEPTION(T)
 
#define ThrowCarmaError(text)
 
#define ThrowCarmaException(exception, text)
 
#define ThrowCarmaUserException(text)
 

Functions

::std::ostream & operator<< (::std::ostream &os, const ::std::exception &error)
 Insert (i.e. output) the error message from any ::std::exception into an output stream. More...
 

Detailed Description

Exception class for errors.

Author
: Steve Scott Original: 08 Oct, 2002 Based on Error.h by Brian Glendenning and BaseException.h by N. S. Amarnath

This class allocates memory to form the final message and is therefore subject to the hazard of running out of resources. If this happens, with a new exception being thrown in the constructor of an exception, then the result is an uncaught exception. You are advised to use carma::util::BaseException if a safer exception is desired.

We use some tricks to ensure that the file name and line number of the location where the exception is created is captured by the exception handler. The actual constructor uses three parameters, but most common use will be via the CARMA_ERROR macro, defined at the end of this file. This macro uses only a single parameter thus allowing it to get the filename and line number at compile time.
The full error message that is created always has the file and line number preceeding the user supplied message.

$CarmaCopyright$

Definition in file ErrorException.h.

Macro Definition Documentation

#define CARMA_ASSERT (   assertion)
Value:
do { \
if ( !(assertion) ) \
throw CARMA_ERROR( #assertion ); \
} while ( false )
#define CARMA_ERROR(y)
Trick to get the file name and line number passed to the exception handler.

Definition at line 189 of file ErrorException.h.

#define CARMA_ERROR (   y)

Trick to get the file name and line number passed to the exception handler.

Definition at line 171 of file ErrorException.h.

#define MAKE_DERIVED_ERROR_EXCEPTION (   T)
Value:
\
class T : public carma::util::ErrorException { \
public: \
\
T( const std::string & os, \
const char * filename, \
const int lineNumber) : \
carma::util::ErrorException( \
( std::string )( #T ) + ": " + os, \
filename, \
lineNumber) \
{ }; \
\
T( const std::ostringstream & os, \
const char * filename, \
const int lineNumber) : \
carma::util::ErrorException( \
( std::string )( #T ) + ": " + os.str(),\
filename, \
lineNumber ) \
{ }; \
\
virtual ~T() throw () \
{ }; \
\
};
Exception class for errors The exception comes with a text string that can be printed or logged...

Definition at line 208 of file ErrorException.h.

#define ThrowCarmaError (   text)
Value:
{\
std::ostringstream _macroOs; \
_macroOs << text;\
throw CARMA_ERROR(_macroOs.str());\
}
#define CARMA_ERROR(y)
Trick to get the file name and line number passed to the exception handler.

Definition at line 175 of file ErrorException.h.

#define ThrowCarmaException (   exception,
  text 
)
Value:
do { \
std::ostringstream _macroOs; \
_macroOs << text; \
throw CARMA_EXCEPTION( exception, _macroOs.str() ); \
} while ( false )
#define CARMA_EXCEPTION(x, y)
Trick to get the file name and line number passed to the exception handler.

Definition at line 198 of file ErrorException.h.

#define ThrowCarmaUserException (   text)
Value:
{\
std::ostringstream _macroOs; \
_macroOs << text;\
throw CARMA_EXCEPTION( carma::util::UserException, _macroOs.str().c_str() );\
}
Generic Carma variant of CORBA::UserException.
#define CARMA_EXCEPTION(x, y)
Trick to get the file name and line number passed to the exception handler.

Definition at line 182 of file ErrorException.h.

Function Documentation

std::ostream & operator<< ( ::std::ostream &  os,
const ::std::exception &  error 
)

Insert (i.e. output) the error message from any ::std::exception into an output stream.

Typical usage is like so:

* ::std::cout << myStdException << ::std::endl;
*
Parameters
osThe output stream to insert the message into.
errorThe exception to get the message from.
Returns
The os output stream parameter so that stream insertions can be chained in the usual C++ way (as shown in the example).