FMT 1.2.0
Forest management tools for forest planning
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Static Protected Attributes | Friends | List of all members
Exception::FMTExceptionHandler Class Referenceabstract

Base class used to handle errors thrown in FMT. More...

#include <FMTExceptionHandler.h>

Inheritance diagram for Exception::FMTExceptionHandler:
[legend]
Collaboration diagram for Exception::FMTExceptionHandler:
[legend]

Public Member Functions

void checkSignals () const
 Check signals in R and Python if on the main thread.
 
 FMTExceptionHandler ()
 Default constructor for FMTExceptionHandler.
 
virtual ~FMTExceptionHandler ()=default
 Default virtual destructor for FMTExceptionHandler.
 
 FMTExceptionHandler (const FMTExceptionHandler &rhs)
 Copy constructor for FMTExceptionHandler.
 
 FMTExceptionHandler (const std::unique_ptr< Logging::FMTLogger > &logger)
 Construct a FMTExceptionHandler with a logger.
 
void passInLogger (const std::unique_ptr< Logging::FMTLogger > &logger)
 Pass a logger to the shared pointer of the handler for sharing.
 
virtual FMTExceptionHandlergetCplData ()
 Return a copy of the abstract handler for use in the FMTCPLErrorHandler function when using GDAL.
 
virtual void handelCplError (int eErrClass, int nError, const char *pszErrorMsg)
 Callback called by GDAL for handling GDAL errors thrown.
 
FMTExceptionHandleroperator= (const FMTExceptionHandler &rhs)
 Default copy assignment operator for FMTExceptionHandler.
 
void throwNested (const std::exception &texception, int &level, bool rethrow=true)
 Throw a nested exception.
 
virtual void printExceptions (std::string text, const std::string &method, const int &line, const std::string &fil, Core::FMTsection lsection=Core::FMTsection::Empty)
 Print all nested exceptions starting with the first provided.
 
virtual FMTException raise (FMTexc lexception, std::string text, const std::string &method, const int &line, const std::string &file, Core::FMTsection lsection=Core::FMTsection::Empty, bool throwit=true)
 Throw a FMTException based on the exception type, section, message and source location. Also used for warnings.
 
virtual FMTException raiseFromCatch (std::string text, const std::string &method, const int &line, const std::string &file, Core::FMTsection lsection=Core::FMTsection::Empty)
 Raise an exception from a catch body, determining if the exception is unhandled.
 
void raiseFromThreadCatch (std::string text, const std::string &method, const int &line, const std::string &file, Core::FMTsection lsection=Core::FMTsection::Empty)
 Raise an exception from a catch body on a worker thread, catching all exceptions and printing them without throwing.
 
void reRaiseIfThreadCrash ()
 Re-raise a multithread error if an exception was raised by any thread.
 
void enableNestedExceptions ()
 Enable the throwing of nested exceptions.
 
void disableNestedExceptions ()
 Disable the throwing of nested exceptions.
 
void setErrorsToWarnings (const std::vector< Exception::FMTexc > &errors)
 Set a list of errors to be cast to warnings.
 
void setMaxWarningsBeforeSilenced (const size_t &maxwarningcount)
 Setter for the maximum number of warnings before they are silenced.
 
virtual std::unique_ptr< FMTExceptionHandlerclone () const =0
 clone the FMTExceptionHandler
 

Static Public Member Functions

static std::string getErrorDescription (bool p_french, FMTexc p_type)
 get descriptions of the potential errors
 
static std::vector< FMTexcgetErrorsToIgnore ()
 gives you a vector of error you can safely turn into warning using setErrorsToWarning return a vector of FMTexc
 

Protected Member Functions

void _updateStatus (std::unique_ptr< FMTException > &p_exception)
 Update the status of the handler of the last exception type thrown and modify if it as to be ignored.
 
bool _needToRethrow () const
 Return true if nested exceptions are used and the exception is a function error that must be rethrown.
 
bool _isMainThread () const
 Return true if we are on the main thread.
 
bool _isThrowedOnThread () const
 Return true if an exception has been thrown on a thread.
 
bool _isThisThreadThrowed () const
 Return true if this thread has thrown.
 
void _registerWorkerThread ()
 Register a worker thread so the handler knows it is dealing with a slave thread and not the main one.
 
bool _isThreadRegistered () const
 Return true if the thread is registered.
 
void _gutsOfPrintExceptions (std::string text, const std::string &method, const int &line, const std::string &fil, int &levelreference, Core::FMTsection lsection=Core::FMTsection::Empty, bool logfirstlevel=true)
 The guts of printExceptions.
 
void _gutsOfExceptionLog (const std::exception &texception, const int &level)
 The guts of logging exceptions.
 
void _updateWarningCount (const FMTException &p_warning)
 update the warning count and print if max not reached
 

Static Protected Member Functions

static std::unique_ptr< FMTException_createException (FMTexc p_exception, Core::FMTsection p_section, const std::string &p_message, const std::string &p_method, const std::string &p_file, int p_line)
 Construct a FMTException from an exception type, a section, a message and the location where it occurred.
 

Protected Attributes

FMTexc _exception
 This is the type of the last FMTException thrown by the FMTExceptionHandler.
 
int _errorcount
 Keeps count of the number of error thrown.
 
size_t m_maxwarningsbeforesilenced
 Number of time that the handler throw a certain warning before stop throwing it.
 
Logging::FMTLogger_logger
 pointer to the logger used to print the warning / error.
 
bool m_usenestedexceptions
 If usenested = true then the handler will throw nested exceptions.
 
boost::recursive_mutex m_mtx
 Mutex for multi-threading.
 
std::vector< Exception::FMTexcm_errorstowarnings
 If an error is in this list it's going to processed like a warning.
 
std::set< boost::thread::id > m_registered_threads
 This is the level of the last FMTException thrown by the FMTExceptionHandler.
 
std::exception_ptr m_threadcrashexception
 The exception throwed by the faulty thread...
 

Static Protected Attributes

static boost::thread::id m_mainthreadid
 Main thread id.
 
static boost::thread::id m_crashedthreadid
 The thread id of the crashed thread.
 

Friends

class boost::serialization::access
 Serialize function used for serialization to do multiprocessing across multiple cpus (pickle in Python).
 

Detailed Description

Base class used to handle errors thrown in FMT.

Keeps count of the warnings and errors thrown and holds a shared pointer to an abstract FMTLogger. Used in the FMTObject class.

Constructor & Destructor Documentation

◆ FMTExceptionHandler() [1/3]

Exception::FMTExceptionHandler::FMTExceptionHandler ( )

Default constructor for FMTExceptionHandler.

◆ ~FMTExceptionHandler()

virtual Exception::FMTExceptionHandler::~FMTExceptionHandler ( )
virtualdefault

Default virtual destructor for FMTExceptionHandler.

◆ FMTExceptionHandler() [2/3]

Exception::FMTExceptionHandler::FMTExceptionHandler ( const FMTExceptionHandler rhs)

Copy constructor for FMTExceptionHandler.

Parameters
[in]rhsthe FMTExceptionHandler to copy.

◆ FMTExceptionHandler() [3/3]

Exception::FMTExceptionHandler::FMTExceptionHandler ( const std::unique_ptr< Logging::FMTLogger > &  logger)

Construct a FMTExceptionHandler with a logger.

Parameters
[in]loggerthe logger to use.

Member Function Documentation

◆ _createException()

static std::unique_ptr< FMTException > Exception::FMTExceptionHandler::_createException ( FMTexc  p_exception,
Core::FMTsection  p_section,
const std::string &  p_message,
const std::string &  p_method,
const std::string &  p_file,
int  p_line 
)
staticprotected

Construct a FMTException from an exception type, a section, a message and the location where it occurred.

Parameters
[in]p_exceptionthe exception type.
[in]p_sectionthe section in which the exception occurred.
[in]p_messagethe message of the exception.
[in]p_methodthe method where the exception occurred.
[in]p_filethe file where the exception occurred.
[in]p_linethe line where the exception occurred.

◆ _gutsOfExceptionLog()

void Exception::FMTExceptionHandler::_gutsOfExceptionLog ( const std::exception &  texception,
const int &  level 
)
protected

The guts of logging exceptions.

Parameters
[in]texceptionthe exception to log.
[in]levelthe nesting level.

◆ _gutsOfPrintExceptions()

void Exception::FMTExceptionHandler::_gutsOfPrintExceptions ( std::string  text,
const std::string &  method,
const int &  line,
const std::string &  fil,
int &  levelreference,
Core::FMTsection  lsection = Core::FMTsection::Empty,
bool  logfirstlevel = true 
)
protected

The guts of printExceptions.

Parameters
[in]textthe message of the exception.
[in]methodthe method where the exception occurred.
[in]linethe line where the exception occurred.
[in]filthe file where the exception occurred.
[in,out]levelreferencethe nesting level reference.
[in]lsectionthe section in which the exception occurred.
[in]logfirstlevelif true logs the first level.

◆ _isMainThread()

bool Exception::FMTExceptionHandler::_isMainThread ( ) const
protected

Return true if we are on the main thread.

Returns
true if on the main thread else false.

◆ _isThisThreadThrowed()

bool Exception::FMTExceptionHandler::_isThisThreadThrowed ( ) const
protected

Return true if this thread has thrown.

Returns
true if this thread has thrown else false.

◆ _isThreadRegistered()

bool Exception::FMTExceptionHandler::_isThreadRegistered ( ) const
protected

Return true if the thread is registered.

Returns
true if the thread is registered else false.

◆ _isThrowedOnThread()

bool Exception::FMTExceptionHandler::_isThrowedOnThread ( ) const
protected

Return true if an exception has been thrown on a thread.

Returns
true if an exception has been thrown on a thread else false.

◆ _needToRethrow()

bool Exception::FMTExceptionHandler::_needToRethrow ( ) const
protected

Return true if nested exceptions are used and the exception is a function error that must be rethrown.

Returns
true if the exception must be rethrown else false.

◆ _registerWorkerThread()

void Exception::FMTExceptionHandler::_registerWorkerThread ( )
protected

Register a worker thread so the handler knows it is dealing with a slave thread and not the main one.

◆ _updateStatus()

void Exception::FMTExceptionHandler::_updateStatus ( std::unique_ptr< FMTException > &  p_exception)
protected

Update the status of the handler of the last exception type thrown and modify if it as to be ignored.

Parameters
[in]p_exceptionthe new exception

◆ _updateWarningCount()

void Exception::FMTExceptionHandler::_updateWarningCount ( const FMTException p_warning)
protected

update the warning count and print if max not reached

Parameters
[in]p_warningthe famous warning

◆ checkSignals()

void Exception::FMTExceptionHandler::checkSignals ( ) const

Check signals in R and Python if on the main thread.

◆ clone()

virtual std::unique_ptr< FMTExceptionHandler > Exception::FMTExceptionHandler::clone ( ) const
pure virtual

◆ disableNestedExceptions()

void Exception::FMTExceptionHandler::disableNestedExceptions ( )

Disable the throwing of nested exceptions.

◆ enableNestedExceptions()

void Exception::FMTExceptionHandler::enableNestedExceptions ( )

Enable the throwing of nested exceptions.

◆ getCplData()

virtual FMTExceptionHandler * Exception::FMTExceptionHandler::getCplData ( )
virtual

Return a copy of the abstract handler for use in the FMTCPLErrorHandler function when using GDAL.

Returns
a pointer to the exception handler.

Reimplemented in Exception::FMTDebugExceptionHandler, Exception::FMTDefaultExceptionHandler, Exception::FMTFreeExceptionHandler, and Exception::FMTQuietExceptionHandler.

◆ getErrorDescription()

static std::string Exception::FMTExceptionHandler::getErrorDescription ( bool  p_french,
FMTexc  p_type 
)
static

get descriptions of the potential errors

Parameters
[in]p_frenchtrue you get it in french
[in]p_exceptionexcpetion type return string description

◆ getErrorsToIgnore()

static std::vector< FMTexc > Exception::FMTExceptionHandler::getErrorsToIgnore ( )
static

gives you a vector of error you can safely turn into warning using setErrorsToWarning return a vector of FMTexc

◆ handelCplError()

virtual void Exception::FMTExceptionHandler::handelCplError ( int  eErrClass,
int  nError,
const char *  pszErrorMsg 
)
virtual

Callback called by GDAL for handling GDAL errors thrown.

Parameters
[in]eErrClassthe error class.
[in]nErrorthe error number.
[in]pszErrorMsgthe error message.

Reimplemented in Exception::FMTDebugExceptionHandler, Exception::FMTDefaultExceptionHandler, Exception::FMTFreeExceptionHandler, and Exception::FMTQuietExceptionHandler.

◆ operator=()

FMTExceptionHandler & Exception::FMTExceptionHandler::operator= ( const FMTExceptionHandler rhs)

Default copy assignment operator for FMTExceptionHandler.

Parameters
[in]rhsthe FMTExceptionHandler to copy.
Returns
a reference to this FMTExceptionHandler.

◆ passInLogger()

void Exception::FMTExceptionHandler::passInLogger ( const std::unique_ptr< Logging::FMTLogger > &  logger)

Pass a logger to the shared pointer of the handler for sharing.

Parameters
[in]loggerthe logger to pass in.

◆ printExceptions()

virtual void Exception::FMTExceptionHandler::printExceptions ( std::string  text,
const std::string &  method,
const int &  line,
const std::string &  fil,
Core::FMTsection  lsection = Core::FMTsection::Empty 
)
virtual

Print all nested exceptions starting with the first provided.

Parameters
[in]textthe message of the exception.
[in]methodthe method where the exception occurred.
[in]linethe line where the exception occurred.
[in]filthe file where the exception occurred.
[in]lsectionthe section in which the exception occurred.

◆ raise()

virtual FMTException Exception::FMTExceptionHandler::raise ( FMTexc  lexception,
std::string  text,
const std::string &  method,
const int &  line,
const std::string &  file,
Core::FMTsection  lsection = Core::FMTsection::Empty,
bool  throwit = true 
)
virtual

Throw a FMTException based on the exception type, section, message and source location. Also used for warnings.

Parameters
[in]lexceptionthe exception type.
[in]textthe message of the exception.
[in]methodthe method where the exception occurred.
[in]linethe line where the exception occurred.
[in]filethe file where the exception occurred.
[in]lsectionthe section in which the exception occurred.
[in]throwitif true throws the exception.
Returns
the raised FMTException.

Reimplemented in Exception::FMTExcelExceptionHandler, Exception::FMTDebugExceptionHandler, Exception::FMTDefaultExceptionHandler, Exception::FMTFreeExceptionHandler, and Exception::FMTQuietExceptionHandler.

◆ raiseFromCatch()

virtual FMTException Exception::FMTExceptionHandler::raiseFromCatch ( std::string  text,
const std::string &  method,
const int &  line,
const std::string &  file,
Core::FMTsection  lsection = Core::FMTsection::Empty 
)
virtual

Raise an exception from a catch body, determining if the exception is unhandled.

Parameters
[in]textthe message of the exception.
[in]methodthe method where the exception occurred.
[in]linethe line where the exception occurred.
[in]filethe file where the exception occurred.
[in]lsectionthe section in which the exception occurred.
Returns
the raised FMTException.

◆ raiseFromThreadCatch()

void Exception::FMTExceptionHandler::raiseFromThreadCatch ( std::string  text,
const std::string &  method,
const int &  line,
const std::string &  file,
Core::FMTsection  lsection = Core::FMTsection::Empty 
)

Raise an exception from a catch body on a worker thread, catching all exceptions and printing them without throwing.

Parameters
[in]textthe message of the exception.
[in]methodthe method where the exception occurred.
[in]linethe line where the exception occurred.
[in]filethe file where the exception occurred.
[in]lsectionthe section in which the exception occurred.

◆ reRaiseIfThreadCrash()

void Exception::FMTExceptionHandler::reRaiseIfThreadCrash ( )

Re-raise a multithread error if an exception was raised by any thread.

◆ setErrorsToWarnings()

void Exception::FMTExceptionHandler::setErrorsToWarnings ( const std::vector< Exception::FMTexc > &  errors)

Set a list of errors to be cast to warnings.

Parameters
[in]errorsthe errors to treat as warnings.

◆ setMaxWarningsBeforeSilenced()

void Exception::FMTExceptionHandler::setMaxWarningsBeforeSilenced ( const size_t &  maxwarningcount)

Setter for the maximum number of warnings before they are silenced.

Parameters
[in]maxwarningcountthe maximum warning count.

◆ throwNested()

void Exception::FMTExceptionHandler::throwNested ( const std::exception &  texception,
int &  level,
bool  rethrow = true 
)

Throw a nested exception.

Parameters
[in]texceptionthe exception to nest.
[in,out]levelthe nesting level.
[in]rethrowif true rethrows the exception.

Friends And Related Function Documentation

◆ boost::serialization::access

friend class boost::serialization::access
friend

Serialize function used for serialization to do multiprocessing across multiple cpus (pickle in Python).

Template Parameters
Archivethe archive type.
Parameters
[in,out]arthe archive to serialize to or from.
[in]versionthe serialization version.

Member Data Documentation

◆ _errorcount

int Exception::FMTExceptionHandler::_errorcount
protected

Keeps count of the number of error thrown.

◆ _exception

FMTexc Exception::FMTExceptionHandler::_exception
protected

This is the type of the last FMTException thrown by the FMTExceptionHandler.

◆ _logger

Logging::FMTLogger* Exception::FMTExceptionHandler::_logger
protected

pointer to the logger used to print the warning / error.

◆ m_crashedthreadid

boost::thread::id Exception::FMTExceptionHandler::m_crashedthreadid
staticprotected

The thread id of the crashed thread.

◆ m_errorstowarnings

std::vector<Exception::FMTexc> Exception::FMTExceptionHandler::m_errorstowarnings
protected

If an error is in this list it's going to processed like a warning.

◆ m_mainthreadid

boost::thread::id Exception::FMTExceptionHandler::m_mainthreadid
staticprotected

Main thread id.

◆ m_maxwarningsbeforesilenced

size_t Exception::FMTExceptionHandler::m_maxwarningsbeforesilenced
protected

Number of time that the handler throw a certain warning before stop throwing it.

◆ m_mtx

boost::recursive_mutex Exception::FMTExceptionHandler::m_mtx
mutableprotected

Mutex for multi-threading.

◆ m_registered_threads

std::set<boost::thread::id> Exception::FMTExceptionHandler::m_registered_threads
protected

This is the level of the last FMTException thrown by the FMTExceptionHandler.

◆ m_threadcrashexception

std::exception_ptr Exception::FMTExceptionHandler::m_threadcrashexception
protected

The exception throwed by the faulty thread...

◆ m_usenestedexceptions

bool Exception::FMTExceptionHandler::m_usenestedexceptions
protected

If usenested = true then the handler will throw nested exceptions.


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