casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Private Attributes | List of all members
AtmException Class Reference

Manage exceptions that raises in ATM. More...

#include <ATMException.h>

Inheritance diagram for AtmException:

Public Member Functions

Constructors and destructor

!

 AtmException (const char *msg) throw ()
 Constructor. More...
 
 AtmException (const char *file, const char *routine, int line, const char *msg) throw ()
 Constructor. More...
 
virtual ~AtmException () throw ()
 Destructor. More...
 
Get attributes

!

virtual const char * file () const throw ()
 Returns the file name where the current error raised. More...
 
virtual const char * routine () const throw ()
 Returns the routine name where the current error raised. More...
 
virtual int line () const throw ()
 Returns the line number where the current error raised. More...
 
virtual const char * message () const throw ()
 Returns the message where the current error raised. More...
 
virtual const char * what () const throw ()
 Returns a string describing the general cause of the current error. More...
 

Private Member Functions

Manage messages

!

string formatMsg (const char *file, const char *routine, int line, const char *msg)
 Output a message that conform to a given trace pattern. More...
 

Private Attributes

string file_m
 The file where the exception raised. More...
 
string routine_m
 The routine where the exception raised. More...
 
int line_m
 The line where the exception raised. More...
 
string msg_m
 The message where the exception raised. More...
 
string what_m
 The error message to be displayed. More...
 

Detailed Description

Manage exceptions that raises in ATM.

Remarks
Don't use a STL container (particularly a std::string) in a catch block of a TelCal exception class because the container may dynamically allocate the memory and so raise a std::exception if the case of std::bad_alloc exception.

To create a AtmException follow the example. The ATM_EXCEPTION_ARGS macro must be used to define the position (file, method and line) where the exception is raised. First include the header file for exceptions.

* #include "ATMException.h"
*

Then create an exception object in a try block. Possibly insert here a log message.

* try
* {
* if(something wrong)
* {
* throw atm::AtmException(ATM_EXCEPTION_ARGS("A message."));
* }
* }
*

If you don't want to indicate the location in the log message then use the message() method instead of what(). Finally catch the exception.

* catch(const atm::AtmException &e)
* {
* // do something like destroy the allocated memory in the try block...
* throw e;
* }
*

In this catch block you can also modify the exception before throwing it. To do it remove the const keyword in the catch call.

The message may be formated using a stream. So first include the needed stream library.

* #include "ATMException.h"
* #include <sstream>
*

Format the message like the following example where x is a variable of miscellaneous type. See following web links:

* std::ostringstream oss;
* oss << "A message " << x << " end of the message.";
* throw atm::AtmException(ATM_EXCEPTION_ARGS(oss.str().c_str()));
*

It is recommended to catch unknown exceptions with an AtmException.

* catch(...)
* {
* throw atm::AtmException(ATM_EXCEPTION_ARGS("Uncaught exception!"));
* }
*

To change the format of the outputed method, change the pattern of trace messages using the telcal::Trace::setTracePattern() method.

Definition at line 118 of file ATMException.h.

Constructor & Destructor Documentation

AtmException::AtmException ( const char *  msg)
throw (
)

Constructor.

Parameters
msga message that describes the exception.
AtmException::AtmException ( const char *  file,
const char *  routine,
int  line,
const char *  msg 
)
throw (
)

Constructor.

Parameters
filethe file name where the exception raised.
routinethe routine name where the exception raised.
linethe line where the exception raised.
msga message that describes the exception.
See Also
formatMsg()

This constructor define the AtmException::what_m attribute using the output string formatted with the formatMsg() method.

virtual AtmException::~AtmException ( )
throw (
)
inlinevirtual

Destructor.

Definition at line 145 of file ATMException.h.

Member Function Documentation

virtual const char* AtmException::file ( ) const
throw (
)
inlinevirtual

Returns the file name where the current error raised.

Returns
A C-style character string.

Definition at line 158 of file ATMException.h.

References file_m.

string AtmException::formatMsg ( const char *  file,
const char *  routine,
int  line,
const char *  msg 
)
private

Output a message that conform to a given trace pattern.

Parameters
filea file name.
routinea routine name.
linea line number.
msga message.
Returns
The formatted message.
virtual int AtmException::line ( ) const
throw (
)
inlinevirtual

Returns the line number where the current error raised.

Returns
An integer.
Remarks
-1 is returned if no line was given.

Definition at line 169 of file ATMException.h.

References line_m.

virtual const char* AtmException::message ( ) const
throw (
)
inlinevirtual

Returns the message where the current error raised.

Returns
A C-style character string.

Definition at line 174 of file ATMException.h.

References msg_m.

virtual const char* AtmException::routine ( ) const
throw (
)
inlinevirtual

Returns the routine name where the current error raised.

Returns
A C-style character string.

Definition at line 163 of file ATMException.h.

References routine_m.

virtual const char* AtmException::what ( ) const
throw (
)
inlinevirtual

Returns a string describing the general cause of the current error.

Returns
A C-style character string.

Definition at line 179 of file ATMException.h.

References what_m.

Member Data Documentation

string AtmException::file_m
private

The file where the exception raised.

Definition at line 199 of file ATMException.h.

Referenced by file().

int AtmException::line_m
private

The line where the exception raised.

Definition at line 201 of file ATMException.h.

Referenced by line().

string AtmException::msg_m
private

The message where the exception raised.

Definition at line 202 of file ATMException.h.

Referenced by message().

string AtmException::routine_m
private

The routine where the exception raised.

Definition at line 200 of file ATMException.h.

Referenced by routine().

string AtmException::what_m
private

The error message to be displayed.

Definition at line 203 of file ATMException.h.

Referenced by what().


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