Orxonox  0.0.5 Codename: Arcturus
Classes | Namespaces | Macros | Functions
Exception.h File Reference

Declaration of facilities to handle exceptions.
More...

#include "UtilPrereqs.h"
#include <exception>
#include <sstream>
#include <string>
#include "Output.h"

Go to the source code of this file.

Classes

class  orxonox::Exception
 Base class for all exceptions (derived from std::exception). More...
 

Namespaces

 orxonox
 Die Wagnis Klasse hat die folgenden Aufgaben:
 

Macros

#define CREATE_ORXONOX_EXCEPTION(ExceptionName)
 Creates a new type of exception that inherits from orxonox::Exception. More...
 
#define ThrowException(type, description)   throw orxonox::exceptionThrowerHelper(type##Exception(static_cast<std::ostringstream&>(std::ostringstream().flush() << description).str(), __LINE__, __FILE__, __FUNCTIONNAME__))
 Throws an exception and logs a message beforehand. More...
 

Functions

 orxonox::CREATE_ORXONOX_EXCEPTION (General)
 
 orxonox::CREATE_ORXONOX_EXCEPTION (FileNotFound)
 
 orxonox::CREATE_ORXONOX_EXCEPTION (Argument)
 
 orxonox::CREATE_ORXONOX_EXCEPTION (PhysicsViolation)
 
 orxonox::CREATE_ORXONOX_EXCEPTION (ParseError)
 
 orxonox::CREATE_ORXONOX_EXCEPTION (PluginsNotFound)
 
 orxonox::CREATE_ORXONOX_EXCEPTION (InitialisationFailed)
 
 orxonox::CREATE_ORXONOX_EXCEPTION (InitialisationAborted)
 
 orxonox::CREATE_ORXONOX_EXCEPTION (NotImplemented)
 
 orxonox::CREATE_ORXONOX_EXCEPTION (GameState)
 
 orxonox::CREATE_ORXONOX_EXCEPTION (NoGraphics)
 
 orxonox::CREATE_ORXONOX_EXCEPTION (AbortLoading)
 
template<class T >
const T & orxonox::exceptionThrowerHelper (const T &exception)
 Helper function that forwards an exception and displays the message. More...
 

Detailed Description

Declaration of facilities to handle exceptions.

Any exception thrown should inherit from orxonox::Exception. There is a macro CREATE_ORXONOX_EXCEPTION to create a new exception (you can find a list of available exceptions in the docs of this file).
Throwing exception is also very simple:

ThrowException(General, "Something went wrong");

(General is a type of exception, see docs of this file)
The exception will automatically contain information about file, line number and function name it occurred in.

There is also some magic you can do for numbers, etc.:

ThrowException(General, "Error code: " << myInt << ". more info...");

It works with an std::ostringstream, so you can feed it all sorts of values.

Macro Definition Documentation

#define CREATE_ORXONOX_EXCEPTION (   ExceptionName)
Value:
class ExceptionName##Exception : public Exception \
{ \
public: \
ExceptionName##Exception(const std::string& description, \
unsigned int lineNumber, const char* filename, \
const char* functionName) \
: Exception(description, lineNumber, filename, functionName) \
{ } \
\
ExceptionName##Exception(const std::string& description) \
: Exception(description) \
{ } \
\
~ExceptionName##Exception() throw() { } \
\
std::string getTypeName() const { return #ExceptionName; } \
}
::std::string string
Definition: gtest-port.h:756

Creates a new type of exception that inherits from orxonox::Exception.

#define ThrowException (   type,
  description 
)    throw orxonox::exceptionThrowerHelper(type##Exception(static_cast<std::ostringstream&>(std::ostringstream().flush() << description).str(), __LINE__, __FILE__, __FUNCTIONNAME__))

Throws an exception and logs a message beforehand.

Parameters
typeType of the exception as literal (General, Initialisation, etc.)
descriptionException description as string
See also
Exception.h