Libthreadar 1.6.0
Public Member Functions | Protected Member Functions | List of all members
libthreadar::exception_base Class Referenceabstract

Pure virtual class parent of all libthreadar exceptions. More...

#include <exceptions.hpp>

Inherited by libthreadar::exception_bug, libthreadar::exception_feature, libthreadar::exception_memory, libthreadar::exception_range, libthreadar::exception_system, and libthreadar::exception_thread.

Public Member Functions

 exception_base (const std::string &x_msg)
 constructor More...
 
 exception_base (const exception_base &ref)=default
 default copy constructor is fine
 
 exception_base (exception_base &&ref) noexcept=default
 default move constructor is fine
 
exception_baseoperator= (const exception_base &ref)=default
 default assignment operator is fine
 
exception_baseoperator= (exception_base &&ref) noexcept=default
 default move operator is fine
 
virtual ~exception_base ()=default
 destructor
 
void push_message (const std::string &x_msg)
 to be used in a catch clause to more detailed information of the problem cause, before rethrowing the exception More...
 
unsigned int size () const
 for site which need to display the information to the user More...
 
const std::string & operator[] (unsigned int i) const
 for site which need to display the information to the user More...
 
std::string get_message (const std::string &sep) const
 concatenated messages and use the given separator between messages More...
 
virtual exception_baseclone () const =0
 create a new object of the same type and value of the object which clone() method is invoked More...
 

Protected Member Functions

void reset_first_message (const std::string &msg)
 for libthreader internal use only More...
 

Detailed Description

Pure virtual class parent of all libthreadar exceptions.

All exception generated by libthreadar follow this interface to provide detailed information about the site of origin of the exception as well as its cause. If the type of exception (see the different exception_* classes that all inherit from class exception_base) is not sufficient for your need and you want a text message of the root cause, all libthreadar exceptions contain a list of messages provided from the source/root cause of the error and completed by messages added by each try/catch block it occured in. You can access these messages by two ways:

You may ignore other features relative to exceptions for normal use of libthreadar

However you are allowed to add new messages to the stack using push_message() and then rethrow the exception for propagation.

Why not concatenating string at each catch{} clause and propagating the exception? Because depending on human languagues, some might well prefer to present this nested informations another way than separating them with ':' from the less specific to the root cause, thus error message translation can be more easy to provide.

Definition at line 87 of file exceptions.hpp.

Constructor & Destructor Documentation

◆ exception_base()

libthreadar::exception_base::exception_base ( const std::string &  x_msg)
inline

constructor

Note
used inside libthreadar only

Definition at line 93 of file exceptions.hpp.

Member Function Documentation

◆ clone()

virtual exception_base * libthreadar::exception_base::clone ( ) const
pure virtual

create a new object of the same type and value of the object which clone() method is invoked

Note
this is true for pointer to inherited class, even if the pointer is of type exception_base the pointed to object will be of the same type of the inherited class

Implemented in libthreadar::exception_memory, libthreadar::exception_bug, libthreadar::exception_thread, libthreadar::exception_system, libthreadar::exception_range, and libthreadar::exception_feature.

◆ get_message()

std::string libthreadar::exception_base::get_message ( const std::string &  sep) const

concatenated messages and use the given separator between messages

Parameters
[in]sepis a string to insert between messages of the list (like for example ": ")
Returns
the resulting error message of the concatenation
Examples
/doc/examples/fast_tampon_example.cpp.

◆ operator[]()

const std::string & libthreadar::exception_base::operator[] ( unsigned int  i) const
inline

for site which need to display the information to the user

Parameters
[in]iis the index of the element of the list to return, it must be stricly lesser than size()
Returns
the requested element of the message list

Definition at line 122 of file exceptions.hpp.

◆ push_message()

void libthreadar::exception_base::push_message ( const std::string &  x_msg)
inline

to be used in a catch clause to more detailed information of the problem cause, before rethrowing the exception

Definition at line 111 of file exceptions.hpp.

◆ reset_first_message()

void libthreadar::exception_base::reset_first_message ( const std::string &  msg)
inlineprotected

for libthreader internal use only

Definition at line 138 of file exceptions.hpp.

◆ size()

unsigned int libthreadar::exception_base::size ( ) const
inline

for site which need to display the information to the user

Returns
the size of the message list

Definition at line 116 of file exceptions.hpp.


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