Core Library  1.7.0.0
Library containing core utilities and tools for threading, networking, logging, INI and CSV file management etc.
core_lib::exceptions::DetailedException Class Reference

Exception class from which to define further derived custom exception classes. More...

#include <DetailedException.h>

Inheritance diagram for core_lib::exceptions::DetailedException:

Public Member Functions

 DetailedException ()=default
 Default constructor.
 
 DetailedException (const std::string &message)
 Initializing constructor. More...
 
 DetailedException (const char *message)
 Initializing constructor. More...
 
 ~DetailedException () noexcept override=default
 Virtual destructor.
 
 DetailedException (const DetailedException &)=default
 Copy constructor.
 
DetailedExceptionoperator= (const DetailedException &)=default
 Copy assignment operator.
 
 DetailedException (DetailedException &&)=default
 Move constructor.
 
DetailedExceptionoperator= (DetailedException &&)=default
 Move assignment operator.
 
char const * what () const NO_EXCEPT_ override
 

Private Attributes

std::string m_what {"exception"}
 

Detailed Description

Exception class from which to define further derived custom exception classes.

This class inherits virtually from std::exception and most importantly boost::exception. Inheriting from the latter ensures that we can get extended information when exceptions are thrown using the boost macro BOOST_THROW_EXCEPTION. The extended information contains line, function and file information of where the exception was thrown, as well as providing access to the what() message.

To access extended info you can do the following:

try
{
BOOST_THROW_EXCEPTION(core_lib::exceptions::DetailedException("something has happened"));
}
{
std::cerr << boost::diagnostic_information(e);
}
catch(...)
{
std::cerr << "Unhandled exception!" << std::endl
<< boost::current_exception_diagnostic_information();
}

This will also work:

try
{
BOOST_THROW_EXCEPTION(core_lib::exceptions::DetailedException("something has happened"));
}
catch(std::exception& e)
{
std::cerr << boost::diagnostic_information(e);
}

And this:

try
{
BOOST_THROW_EXCEPTION(core_lib::exceptions::DetailedException("something has happened"));
}
catch(boost::exception& e)
{
std::cerr << boost::diagnostic_information(e);
}

And lastly this:

try
{
BOOST_THROW_EXCEPTION(core_lib::exceptions::DetailedException("something has happened"));
}
catch(...)
{
std::cerr << "Unhandled exception!" << std::endl
<< boost::current_exception_diagnostic_information();
}

This class is defined inline to make exporting from a DLL containing this class trivial as we are deriving from boost::exception and std::exception.

Constructor & Destructor Documentation

◆ DetailedException() [1/2]

core_lib::exceptions::DetailedException::DetailedException ( const std::string &  message)
inlineexplicit

Initializing constructor.

Parameters
[in]message- A user specified message string.

◆ DetailedException() [2/2]

core_lib::exceptions::DetailedException::DetailedException ( const char *  message)
inlineexplicit

Initializing constructor.

Parameters
[in]message- A user specified message string.

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