AAO DRAMA/DRAMA2 C++ Interface
DRAMA C++11 and later interface
Public Member Functions | List of all members
drama::Exception Class Reference

Detailed Description

An Exception class for exceptions thrown by DRAMA V2 classes.

DRAMA Traditionally uses an inherited status error handing convention. The DRAMA V2 classes will convert any error status from the underlying C libraries into an exception of this class (or a sub-class).

The underlying DRAMA Status is saved, and generally extra text is added at the point of the throw, as well as the line number and file where the throw was generated.

To throw an exception, construct objects of this class They allow conextual information to be provided (C++ source file, source line number and a message) to be provided with the exception. Then throw the object. Between constructing and throwing, other information can be added. The information is available to catching functions via the toString() method.

It is expected that all DRAMA 2 classes throw exceptions using this exception or sub-classes of it.

Two macros are provides which implement a simple interface to throwing these exceptions. DramaTHROW() needs only a DRAMA status and a contextual message, automatically inserting the C++ source file details. DramaTHROW_S() is similar except that message can include format characters with extra arguments added.

A stack-trace is also generated to help work out the location of the throw. This provides the best information if the program is linked with the "-rdynamic" option (at least, under gcc on linux, other cases to be determined).

Methods are provided which allow information the DRAMA C level Error Reporting System (ERS) to be added to the exception, and also too allow the exception information to be output to ERS. This allows transfer across C/C++ boundaries in either direction.

A << class operator allows any type supported by sstream to be written to the exception message. Various other ways of writing to the exception message are provided, such as FmtWrite().

An (non class) << operator allows the exception details to be written to a C++ ostream. Various other output methods are provided.

Author
Tony Farrell, AAO $Revision$ $Date$
Examples
argtest.cpp, dramahello.cpp, monitor1.cpp, monitor2.cpp, threadbasic.cpp, and tocker.cpp.

#include "exception.hh"

Inheritance diagram for drama::Exception:

Public Member Functions

 Exception ()
 Create an Exception, details empty.
 
D2DEPRECATED Exception (bool makeUnique, const std::string func, const std::string &file, const int lineNum, const StatusType status, const char *format,...)
 Create an exception using C printf() style string formatting.
 
 Exception (const Exception &source)
 Copy constructor.
 
 Exception (const std::string func, const std::string &file, const int lineNum, const std::string &message="", const StatusType status=DRAMA2__CPP_ERROR, const bool alwaysStacktrace=false)
 Create an Exception.
 
 Exception (Exception &&source) noexcept
 Move constructor.
 
virtual ~Exception ()
 Virtual Destructor - since we will be inherited.
 
void AddErs ()
 Add the any errors from the current ERS context to the exception.
 
virtual StatusType dramaStatus () const
 Return the DRAMA Status code associated with the exception.
 
virtual std::string dramaStatusStr () const
 Return the DRAMA Status code converted to a DRAMA.
 
virtual void ErsOut () const
 Output a DRAMA ERS report about this exception.
 
virtual void ErsRep () const
 Report details of this exception using ERS.
 
virtual const std::string & fileName () const
 Returns the name of the C++ source file in which the exception occurred.
 
template<typename T , typename... Types>
void FmtWrite (const char *format, T value, Types... args)
 Safe formated write to an exception message string.
 
void FmtWrite (const char *str)
 Safe formatted write to an exception message string.
 
virtual const std::string & function () const
 Returns the name of the function in which the exception occurred.
 
virtual const std::string & getOrigMessage () const
 Returns the exception original message.
 
virtual std::string getStackTrace () const
 Return the stack trace created when the exception was created.
 
virtual int lineNumber () const
 Returns the source file line number at which the exception occurred.
 
template<class T >
Exceptionoperator<< (const T &t)
 Add extra information to an exception message.
 
Exceptionoperator= (const Exception &rhs)
 Assignment operator.
 
Exceptionoperator= (Exception &&rhs) noexcept
 Move assignment operator.
 
virtual void Print (FILE *file=stderr, bool include_stacktrace=false) const
 Print exception details to a file.
 
virtual int statusAsSysExitCode () const
 Return a system exit code based on the DRAMA Status.
 
virtual std::string toString () const
 Return the exception string.
 
const charwhat () const noexcept override
 Get string identifying exception.
 

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