MoReFEM
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes
MoReFEM::Exception Class Reference

Generic class for MoReFEM exceptions. More...

#include <Exception.hpp>

Inheritance diagram for MoReFEM::Exception:
Collaboration diagram for MoReFEM::Exception:

Public Member Functions

virtual const char * what () const noexcept override final
 Display the what message from std::exception.
 
const std::string & GetRawMessage () const noexcept
 Display the raw message (Without file and line).
 
Special members.
 Exception (const std::string &msg, const std::source_location location=std::source_location::current())
 Constructor with simple message.
 
virtual ~Exception () noexcept override
 Destructor.
 
 Exception (const Exception &rhs)=default
 The copy constructor.
 
 Exception (Exception &&rhs)=default
 The move constructor.
 
Exceptionoperator= (const Exception &rhs)=default
 The (copy) operator=.
 
Exceptionoperator= (Exception &&rhs)=default
 The (move) operator=.
 

Private Attributes

std::string what_message_
 The complete what() message (with the location part)
 
std::string raw_message_
 Incomplete message (might be useful if we catch an exception to tailor a more specific message).
 

Detailed Description

Generic class for MoReFEM exceptions.

Constructor & Destructor Documentation

◆ Exception() [1/3]

MoReFEM::Exception::Exception ( const std::string & msg,
const std::source_location location = std::source_location::current() )
explicit

Constructor with simple message.

Parameters
[in]msgMessage.
Parameters
[in]locationSTL object with relevant information about the calling site (usually to help when an exception is thrown.

◆ ~Exception()

virtual MoReFEM::Exception::~Exception ( )
overridevirtualnoexcept

◆ Exception() [2/3]

MoReFEM::Exception::Exception ( const Exception & rhs)
default

The copy constructor.

Parameters
[in]rhsThe object from which the construction occurs.

◆ Exception() [3/3]

MoReFEM::Exception::Exception ( Exception && rhs)
default

The move constructor.

Parameters
[in]rhsThe object from which the construction occurs.

Member Function Documentation

◆ operator=() [1/2]

Exception & MoReFEM::Exception::operator= ( const Exception & rhs)
default

The (copy) operator=.

Parameters
[in]rhsThe object from which the affectation occurs.
Returns
Reference to the object (to enable chained affectation).

◆ operator=() [2/2]

Exception & MoReFEM::Exception::operator= ( Exception && rhs)
default

The (move) operator=.

Parameters
[in]rhsThe object from which the affectation occurs.
Returns
Reference to the object (to enable chained affectation).

◆ what()

virtual const char * MoReFEM::Exception::what ( ) const
finaloverridevirtualnoexcept

Display the what message from std::exception.

Returns
The what() message as a char* (which reads the internal std::string so no risk of deallocation issue).

◆ GetRawMessage()

const std::string & MoReFEM::Exception::GetRawMessage ( ) const
noexcept

Display the raw message (Without file and line).

Might be useful if exception is caught to rewrite a more refined message.

Before introducing this, we could end up in some cases with something like:

* Exception caught: Exception found at Sources/Model/Internal/InitializeHelper.hxx, line 114: Ill-defined
* finite element space 1: Exception found at Sources/Model/Internal/InitializeHelper.hxx, line 101:
* Domain 1 is not defined!
* 

Clearly it is nicer to provide:

* Exception caught: Exception found at Sources/Model/Internal/InitializeHelper.hxx, line 114: Ill-defined
* finite element space 1: Domain 1 is not defined!
* 
Returns
Exception error message without information about file and line in which the exception was invoked.

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