TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
triqs::exception

#include <triqs/utility/exceptions.hpp>

Detailed Description

Base class for exceptions thrown in TRIQS.

A triqs::exception carries a std::stringstream accumulator that the user can extend with operator<<(). When what() is called, the accumulated message is returned, followed by the rank of the throwing MPI process and (if the environment variable TRIQS_SHOW_EXCEPTION_TRACE is set) by the C++ stack trace captured at construction.

Definition at line 75 of file exceptions.hpp.

Inheritance diagram for triqs::exception:
triqs::keyboard_interrupt triqs::runtime_error

Public Member Functions

 exception () noexcept
 Default constructor ceates an exception with an empty diagnostic message and an empty stack trace.
 exception (exception const &e) noexcept
 Copy constructor copies the accumulated diagnostic message, the captured stack trace and the cached what() string from another exception.
virtual ~exception () noexcept
 Virtual default destructor.
exceptionoperator<< (const char *mess)
 Append a C string to the accumulated diagnostic message.
template<typename T>
exceptionoperator<< (T const &x)
 Append a value to the accumulated diagnostic message.
virtual const char * trace () const noexcept
 Get the captured stack trace.
virtual const char * what () const noexcept
 Build and return the full diagnostic message.

Constructor & Destructor Documentation

◆ exception()

triqs::exception::exception ( exception const & e)
inlinenoexcept

Copy constructor copies the accumulated diagnostic message, the captured stack trace and the cached what() string from another exception.

Parameters
eException to copy from.

Definition at line 90 of file exceptions.hpp.

Member Function Documentation

◆ operator<<() [1/2]

exception & triqs::exception::operator<< ( const char * mess)
inline

Append a C string to the accumulated diagnostic message.

Parameters
messNull-terminated C string to append to the message.
Returns
Reference to *this to allow chaining of multiple operator<<() calls.

Definition at line 115 of file exceptions.hpp.

◆ operator<<() [2/2]

template<typename T>
exception & triqs::exception::operator<< ( T const & x)
inline

Append a value to the accumulated diagnostic message.

The value is streamed into the internal std::stringstream accumulator.

Template Parameters
TType streamable into a std::ostream.
Parameters
xValue to append to the message.
Returns
Reference to *this to allow chaining of multiple operator<<() calls.

Definition at line 104 of file exceptions.hpp.

◆ trace()

virtual const char * triqs::exception::trace ( ) const
inlinevirtualnoexcept

Get the captured stack trace.

Returns
Null-terminated C string holding the C++ stack trace (empty if none was captured).

Definition at line 142 of file exceptions.hpp.

◆ what()

virtual const char * triqs::exception::what ( ) const
inlinevirtualnoexcept

Build and return the full diagnostic message.

Concatenates the accumulated message, the rank of the throwing MPI process (when MPI is initialized) and, if the environment variable TRIQS_SHOW_EXCEPTION_TRACE is set, the captured C++ stack trace. The result is cached in a member so the returned pointer stays valid for the lifetime of the exception object.

Returns
Null-terminated string owned by the exception object.

Definition at line 129 of file exceptions.hpp.


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