CARMA C++
carma::util::BaseException Class Reference

Base exception class for managing carma errors. More...

#include <carma/util/BaseException.h>

Inheritance diagram for carma::util::BaseException:
carma::antenna::bima::SharedMemoryException carma::monitor::IllegalMonitorPointExceptionObj carma::monitor::SampleInvalidExceptionObj carma::util::ErrorException carma::util::SystemException carma::dbms::DBConnectionException carma::dbms::MalformedSyslogLineException carma::dbms::MPMLException carma::dbms::SQLException carma::monitor::NullEventException carma::monitor::ReachedNumThresholdLimitException carma::monitor::ThresholdObjectNotFoundException carma::services::ConformabilityException carma::services::EphemerisException carma::services::UnsupportedCoordSysException carma::util::EOFException carma::util::FileExistsException carma::util::IllegalArgumentException carma::util::IllegalStateException carma::util::NotFoundException carma::util::NumberFormatException carma::util::SemaphoreException carma::util::SemaphoreTimedOutException

Public Member Functions

Backtrace getBacktrace () const
 
virtual int getLineNumber () const
 
virtual ::std::string getLogString () const
 
virtual const char * getMessage () const
 
virtual const char * getSourceFile () const
 
void logException (log4cpp::Priority::PriorityLevel priority) const
 
virtual void setMessageDirectly (const char *mesg)
 
virtual void setMessageToCopy (const char *mesg)
 
virtual void setMessageToCopy (const ::std::string &mesg)
 
virtual void setMessageToCopy (const ::std::ostringstream &oss)
 
virtual const char * what () const throw ( )
 
virtual ~BaseException () throw ( )
 

Protected Member Functions

 BaseException (const BaseException &rhs)
 
 BaseException (const char *mesg, const char *fileName, const int lineNo)
 Constructor - creates an instance of class BaseException. More...
 
 BaseException (const char *mesg, const ::std::string &fileName, const int lineNo)
 
 BaseException (const ::std::string &mesg, const char *fileName, const int lineNo)
 
 BaseException (const ::std::string &mesg, const ::std::string &fileName, const int lineNo)
 
 BaseException (const ::std::ostringstream &oss, const char *fileName, const int lineNo)
 
 BaseException (const ::std::ostringstream &oss, const ::std::string &fileName, const int lineNo)
 
BaseExceptionoperator= (const BaseException &rhs)
 
virtual void setLineNumber (int num)
 
void setSourceFileDirectly (const char *file)
 
void setSourceFileToCopy (const char *file)
 
void setSourceFileToCopy (const ::std::string &file)
 

Related Functions

(Note that these are not member 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

Base exception class for managing carma errors.

Includes facilities for specifying and logging error messages to a default process wide carma logger.

Definition at line 48 of file BaseException.h.

Constructor & Destructor Documentation

virtual carma::util::BaseException::~BaseException ( )
throw (
)
virtual

Destructor for BaseException.

carma::util::BaseException::BaseException ( const char *  mesg,
const char *  fileName,
const int  lineNo 
)
protected

Constructor - creates an instance of class BaseException.

Users should use the macro definition (see the #define towards the end of this file).

Parameters
mesgThe message to be logged for this exception. If the exception is to be caught outside the scope of the function where the exception was constructed, then 'mesg' should not be a stack variable. Stack variables are lost as the exception unwinds stacks on its way to the catcher.
fileNameThe source file containing the code throwing the exception - can be set using the cpp macro 'FILE'.
lineNoThe line number in the source file where the exception is created - should use the cpp macro 'LINE'.
Returns
none.

Member Function Documentation

virtual int carma::util::BaseException::getLineNumber ( ) const
virtual

getLineNumber - gets the number of the line within the source file where the exception was created. Intended to be used as a means of recording the location where the exception was thrown. This line number is set as a parameter in the public constructor - should use the cpp macro 'LINE'.

Returns
line number as an integer.
virtual const char* carma::util::BaseException::getMessage ( ) const
virtual

getMessage - gets error message set within this instance of class BaseException. This message may be logged when the exception is caught. BaseException::setMessage is used to set the message.

Returns
error message as a constant char*.
virtual const char* carma::util::BaseException::getSourceFile ( ) const
virtual

getSourceFile - gets the name of the source file where this exception was created. Intended to be used as a means of recording the location where the exception was thrown. The name of the source file is set as a parameter in the public constructor - should use the cpp macro 'FILE'.

Returns
source file name as a constant char*.
void carma::util::BaseException::logException ( log4cpp::Priority::PriorityLevel  priority) const

logException - logs the message associated with this instance of BaseException. Message is logged with the source file name and line number of the location where this exception was constructed. The message is logged using the carma::util::Logger associated with the current process.

Parameters
priorityPriority of the message to be logged, as a variable of type log4cpp::Priority.
Returns
none.
virtual void carma::util::BaseException::setLineNumber ( int  num)
protectedvirtual

setLineNumber - gets the number of the line within the source file where the exception was created. Intended to be used as a means of recording the location where the exception was thrown. This line number is set as a parameter in the public constructor - should use the cpp macro 'LINE'.

virtual void carma::util::BaseException::setMessageDirectly ( const char *  mesg)
virtual

setMessage - sets error message within this instance of class BaseException. This message may be logged when the exception is caught. BaseException::getMessage also returns the message. setMessage does not make a local copy of the string as we want to minimize the potential for exceptions generated by operations in BaseException.

Parameters
mesgThe message to be logged for this exception.
Returns
none.
virtual void carma::util::BaseException::setMessageToCopy ( const ::std::string &  mesg)
virtual

setMessage - sets error message within this instance of class BaseException. This message may be logged when the exception is caught. BaseException::getMessage also returns the message.

Parameters
istringA string containing the message to be logged for this exception.
Returns
none.
virtual void carma::util::BaseException::setMessageToCopy ( const ::std::ostringstream &  oss)
virtual

setMessage - sets error message within this instance of class BaseException. This message may be logged when the exception is caught. BaseException::getMessage also returns the message.

Parameters
streamA stream containing the message to be logged for this exception.
Returns
none.
void carma::util::BaseException::setSourceFileDirectly ( const char *  file)
protected

setSourceFile - gets the name of the source file where this exception was created. Intended to be used as a means of recording the location where the exception was thrown. The name of the source file is set as a parameter in the public constructor - should use the cpp macro 'FILE'.

Returns
source file name as a constant char*.
virtual const char* carma::util::BaseException::what ( ) const
throw (
)
virtual

what - returns full text of message to be logged. BaseException.

Todo:
Must complete this function. For now, just returns message set using setMessage, or constructor. Must instead return string(?) with full text.
Returns
full text of error message as const char*.
Exceptions
undefinedexception thrown - required for compatibility with std::exception.

Reimplemented in carma::antenna::bima::SharedMemoryException, and carma::util::ErrorException.

Friends And Related Function Documentation

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

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).

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