AutoPas  3.0.0
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Member Functions | List of all members
autopas::utils::ExceptionHandler Class Reference

Defines and handles the throwing and printing of exceptions. More...

#include <ExceptionHandler.h>

Classes

class  AutoPasException
 Default exception class for autopas exceptions. More...
 

Public Member Functions

template<>
void exception (const std::string e)
 Handles an exception that is defined using the input string.
 
template<>
void exception (const char *const e)
 Handles an exception that is defined using the input string.
 

Static Public Member Functions

static void setBehavior (ExceptionBehavior behavior)
 Set the behavior of the handler.
 
template<class Exception >
static void exception (const Exception e)
 Handle an exception derived by std::exception.
 
template<typename First , typename... Args>
static void exception (std::string exceptionString, First first, Args... args)
 Handles an exception that is defined using exceptionString as well as multiple arguments.
 
static void rethrow ()
 Rethrows the current exception or prints it.
 
static void setCustomAbortFunction (std::function< void()> function)
 Set a custom abort function.
 

Detailed Description

Defines and handles the throwing and printing of exceptions.

This class defines what should happen if an error occurs within AutoPas. For a detailed list please check the enum ExceptionBehavior

Member Function Documentation

◆ exception() [1/4]

template<>
void autopas::utils::ExceptionHandler::exception ( const char *const  e)

Handles an exception that is defined using the input string.

Parameters
ethe string to describe the exception

◆ exception() [2/4]

template<class Exception >
static void autopas::utils::ExceptionHandler::exception ( const Exception  e)
inlinestatic

Handle an exception derived by std::exception.

If the behavior is set to throw and this function is called in a catch clause, instead of using the passed exception the underlying error is rethrown.

Parameters
ethe exception to be handled
Template Parameters
Exceptionthe type of the exception, needed as throw only uses the static type of e

◆ exception() [3/4]

template<>
void autopas::utils::ExceptionHandler::exception ( const std::string  e)

Handles an exception that is defined using the input string.

Parameters
ethe string to describe the exception

◆ exception() [4/4]

template<typename First , typename... Args>
void autopas::utils::ExceptionHandler::exception ( std::string  exceptionString,
First  first,
Args...  args 
)
static

Handles an exception that is defined using exceptionString as well as multiple arguments.

It uses the same fmt library that is also used in spdlog and AutoPasLogger. Call it using e.g.: exception("failure, because {} is not less than {}", 4, 3);

Template Parameters
Firstthe template type of the first argument
Argstypes of multiple
Parameters
exceptionStringthe basic exception string
firstthe first argument
argsmore arguments
Note
First is needed to differentiate this from the template with exception(const Exception e)
this is a variadic function, and can thus incorporate an arbitrary amount of arguments

◆ rethrow()

void autopas::utils::ExceptionHandler::rethrow ( )
static

Rethrows the current exception or prints it.

Depending on the set behavior the currently active exception is either rethrown, printed or otherwise handled.

Note
Use this only inside a catch clause.

◆ setBehavior()

void autopas::utils::ExceptionHandler::setBehavior ( ExceptionBehavior  behavior)
static

Set the behavior of the handler.

Parameters
behaviorthe behavior

◆ setCustomAbortFunction()

void autopas::utils::ExceptionHandler::setCustomAbortFunction ( std::function< void()>  function)
static

Set a custom abort function.

Parameters
functionthe custom abort function

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