Gromacs  2022.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions
gmx::test::TestException Class Reference

#include <testutils/include/testutils/testexceptions.h>

+ Inheritance diagram for gmx::test::TestException:
+ Collaboration diagram for gmx::test::TestException:

Description

Exception class for reporting errors in tests.

This exception should be used for error conditions that are internal to the test, i.e., do not indicate errors in the tested code.

Public Member Functions

 TestException (const std::string &reason)
 Creates a test exception object with the provided detailed reason. More...
 
 TestException (const GromacsException &base)
 Creates a test exception based on another GromacsException object. More...
 
int errorCode () const override
 Returns the error code corresponding to the exception type.
 
const char * what () const noexceptoverride
 Returns the reason string for the exception. More...
 
template<class InfoType >
const InfoType::value_type * getInfo () const
 Returns the value associated with given ExceptionInfo. More...
 
template<class Tag , typename T >
void setInfo (const ExceptionInfo< Tag, T > &item)
 Associates extra information with the exception. More...
 
void prependContext (const std::string &context)
 Adds context information to this exception. More...
 

Constructor & Destructor Documentation

gmx::test::TestException::TestException ( const std::string &  reason)
inlineexplicit

Creates a test exception object with the provided detailed reason.

Parameters
[in]reasonDetailed reason for the exception.
gmx::test::TestException::TestException ( const GromacsException base)
inlineexplicit

Creates a test exception based on another GromacsException object.

Parameters
[in]baseException to wrap.
See Also
GMX_THROW_WRAPPER_TESTEXCEPTION

Member Function Documentation

template<class InfoType >
const InfoType::value_type* gmx::GromacsException::getInfo ( ) const
inlineinherited

Returns the value associated with given ExceptionInfo.

Template Parameters
InfoTypeExceptionInfo type to get the value for.
Returns
Value set for InfoType, or nullptr if such info has not been set.

Does not throw.

void gmx::GromacsException::prependContext ( const std::string &  context)
inherited

Adds context information to this exception.

Parameters
[in]contextContext string to add.
Exceptions
std::bad_allocif out of memory.

Typical use is to add additional information higher up in the call stack using this function in a catch block and the rethrow the exception.

Todo:
The added information is currently not accessible through what(), nor through any other means except for calling printFatalErrorMessage(), formatExceptionMessageToString() or formatExceptionMessageToFile(). See ExceptionInitializer for more discussion.
template<class Tag , typename T >
void gmx::GromacsException::setInfo ( const ExceptionInfo< Tag, T > &  item)
inlineinherited

Associates extra information with the exception.

Template Parameters
TagExceptionInfo tag type.
TExceptionInfo value type.
Parameters
[in]itemExceptionInfo to associate.
Exceptions
std::bad_allocif out of memory.
unspecifiedany exception thrown by T copy construction.

If an item of this type is already associated, it is overwritten.

const char * gmx::GromacsException::what ( ) const
overridenoexceptinherited

Returns the reason string for the exception.

The return value is the string that was passed to the constructor.


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