OpenMS
Loading...
Searching...
No Matches
GlobalExceptionHandler Class Reference

OpenMS global exception handler. More...

#include <OpenMS/CONCEPT/GlobalExceptionHandler.h>

Static Protected Member Functions

Wrapper for static member.
Note
To avoid problems when accessing uninitialised static members we replaced them with static functions returning references to the members. Each member is thread-local.
static std::string & file_ ()
 wrapper for static member file_
 
static int & line_ ()
 wrapper for static member line_
 
static std::string & function_ ()
 wrapper for static member function_
 
static std::string & name_ ()
 wrapper for static member name_
 
static std::string & what_ ()
 wrapper for static member what_
 

Constructors

 GlobalExceptionHandler () throw ()
 Default constructor.
 
 GlobalExceptionHandler (const GlobalExceptionHandler &)
 private version of c'tor to avoid initialization
 
 ~GlobalExceptionHandler ()
 
static GlobalExceptionHandler & getInstance ()
 The accessor for the singleton. It also serves as a replacement for the constructor.
 

Accessors

static void setName (const std::string &name) throw ()
 
static void setMessage (const std::string &message) throw ()
 
static void setLine (int line) throw ()
 
static void setFile (const std::string &file) throw ()
 
static void setFunction (const std::string &function) throw ()
 
static void set (const std::string &file, int line, const std::string &function, const std::string &name, const std::string &message) throw ()
 
static void terminate () throw ()
 The OPENMS replacement for terminate.
 
static void newHandler ()
 The OPENMS new handler.
 

Detailed Description

OpenMS global exception handler.

The last exception constructed is recorded per thread (the fields below are thread-local), so exceptions thrown at the same time on several threads do not write the same state. terminate() reports the entry of the thread it runs on, i.e. the one whose exception was not caught.

Constructor & Destructor Documentation

◆ GlobalExceptionHandler() [1/2]

GlobalExceptionHandler ( )
throw (
)
private

Default constructor.

This constructor installs the OPENMS specific handlers for terminate, unexpected, and new_handler. terminate or unexpected are called to abort a program if an exception was not caught or a function exits via an exception that is not allowed by its exception specification. Both functions are replaced by a function of GlobalExceptionHandler that tries to determine the last exception thrown. This mechanism only works, if all exceptions are derived from Base.

The default new_handler is replaced by newHandler and throws an exception of type OutOfMemory instead of bad_alloc (the default behaviour defined in the ANSI C++ standard).

◆ GlobalExceptionHandler() [2/2]

GlobalExceptionHandler ( const GlobalExceptionHandler &  )
inlineprivate

private version of c'tor to avoid initialization

◆ ~GlobalExceptionHandler()

~GlobalExceptionHandler ( )
inlineprivate

Member Function Documentation

◆ file_()

static std::string & file_ ( )
staticprotected

wrapper for static member file_

◆ function_()

static std::string & function_ ( )
staticprotected

wrapper for static member function_

◆ getInstance()

static GlobalExceptionHandler & getInstance ( )
static

The accessor for the singleton. It also serves as a replacement for the constructor.

◆ line_()

static int & line_ ( )
staticprotected

wrapper for static member line_

◆ name_()

static std::string & name_ ( )
staticprotected

wrapper for static member name_

◆ newHandler()

static void newHandler ( )
staticprotected

The OPENMS new handler.

◆ set()

static void set ( const std::string &  file,
int  line,
const std::string &  function,
const std::string &  name,
const std::string &  message 
)
throw (
)
static

◆ setFile()

static void setFile ( const std::string &  file)
throw (
)
static

◆ setFunction()

static void setFunction ( const std::string &  function)
throw (
)
static

◆ setLine()

static void setLine ( int  line)
throw (
)
static

◆ setMessage()

static void setMessage ( const std::string &  message)
throw (
)
static

◆ setName()

static void setName ( const std::string &  name)
throw (
)
static

◆ terminate()

static void terminate ( )
throw (
)
staticprotected

The OPENMS replacement for terminate.

◆ what_()

static std::string & what_ ( )
staticprotected

wrapper for static member what_