MarlinMT  0.1.0
marlinmt::Exception Class Reference

Exception class. More...

#include <Exceptions.h>

Inherits exception.

Public Member Functions

 Exception ()=delete
 
 Exception (const Exception &)=default
 
virtual ~Exception ()=default
 
 Exception (const std::string &message)
 Constructor. More...
 
 Exception (unsigned int line, const std::string &func, const std::string &fname, const std::string &message)
 Constructor. More...
 
template<typename T >
 Exception (const T &rhs, unsigned int line, const std::string &func, const std::string &fname, const std::string &message)
 Constructor. More...
 
const char * what () const noexcept override
 Get the full exception message. More...
 

Protected Member Functions

std::string createMessage (unsigned int line, const std::string &func, const std::string &fname, const std::string &message) const
 Helper function creating the full exception message. More...
 
std::string createMessage (const std::string &previous, unsigned int line, const std::string &func, const std::string &fname, const std::string &message) const
 Helper function creating the full exception message. More...
 

Protected Attributes

const std::string _message {}
 < The full exception message More...
 

Detailed Description

Exception class.

Smart exception class. Tracking of:

  • file name
  • line number
  • function name of the exception location. The exception message can be stack with any other previously thrown exception. Use the pre-processor macro to throw an exception:
    MARLINMT_THROW( "A problem occured" );
    An exception can rethrown:
    try {
    // ... some code
    }
    catch ( const marlinmt::Exception &e ) {
    MARLINMT_RETHROW( e, "A problem occured" );
    }
    In this case, the message will appended to the previous exception message

Definition at line 60 of file Exceptions.h.

Constructor & Destructor Documentation

◆ Exception() [1/5]

marlinmt::Exception::Exception ( )
delete

◆ Exception() [2/5]

marlinmt::Exception::Exception ( const Exception )
default

◆ ~Exception()

virtual marlinmt::Exception::~Exception ( )
virtualdefault

◆ Exception() [3/5]

marlinmt::Exception::Exception ( const std::string &  message)

Constructor.

Parameters
messagethe exception message

Definition at line 5 of file Exceptions.cc.

◆ Exception() [4/5]

marlinmt::Exception::Exception ( unsigned int  line,
const std::string &  func,
const std::string &  fname,
const std::string &  message 
)

Constructor.

Parameters
linethe exception line number
functhe function name in which the exception has been thrown
fnamethe file in which the exception has been thrown
messagethe exception message

Definition at line 12 of file Exceptions.cc.

◆ Exception() [5/5]

template<typename T >
marlinmt::Exception::Exception ( const T &  rhs,
unsigned int  line,
const std::string &  func,
const std::string &  fname,
const std::string &  message 
)
inline

Constructor.

Parameters
rhsany possible class having a method what() returning a string
linethe exception line number
functhe function name in which the exception has been thrown
fnamethe file in which the exception has been thrown
messagethe exception message

Definition at line 131 of file Exceptions.h.

References marlinmt::MARLINMT_DEFINE_EXCEPTION().

Member Function Documentation

◆ createMessage() [1/2]

std::string marlinmt::Exception::createMessage ( unsigned int  line,
const std::string &  func,
const std::string &  fname,
const std::string &  message 
) const
protected

Helper function creating the full exception message.

Parameters
linethe exception line number
functhe function name in which the exception has been thrown
fnamethe file in which the exception has been thrown
messagethe exception message

Definition at line 25 of file Exceptions.cc.

Referenced by createMessage().

◆ createMessage() [2/2]

std::string marlinmt::Exception::createMessage ( const std::string &  previous,
unsigned int  line,
const std::string &  func,
const std::string &  fname,
const std::string &  message 
) const
protected

Helper function creating the full exception message.

Parameters
aprevious message to prepend in the message (plus a line break)
linethe exception line number
functhe function name in which the exception has been thrown
fnamethe file in which the exception has been thrown
messagethe exception message

Definition at line 31 of file Exceptions.cc.

References createMessage().

◆ what()

const char * marlinmt::Exception::what ( ) const
overridenoexcept

Get the full exception message.

Definition at line 19 of file Exceptions.cc.

References _message.

Referenced by marlinmt::Application::main().

Member Data Documentation

◆ _message

const std::string marlinmt::Exception::_message {}
protected

< The full exception message

Definition at line 124 of file Exceptions.h.

Referenced by what().


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