![]() |
FMT 1.2.0
Forest management tools for forest planning
|
Base class used to handle errors thrown in FMT. More...
#include <FMTExceptionHandler.h>
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 FMTExceptionHandler * | getCplData () |
| 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. | |
| FMTExceptionHandler & | operator= (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< FMTExceptionHandler > | clone () 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< FMTexc > | getErrorsToIgnore () |
| 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::FMTexc > | m_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). | |
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.
| Exception::FMTExceptionHandler::FMTExceptionHandler | ( | ) |
Default constructor for FMTExceptionHandler.
|
virtualdefault |
Default virtual destructor for FMTExceptionHandler.
| Exception::FMTExceptionHandler::FMTExceptionHandler | ( | const FMTExceptionHandler & | rhs | ) |
Copy constructor for FMTExceptionHandler.
| [in] | rhs | the FMTExceptionHandler to copy. |
| Exception::FMTExceptionHandler::FMTExceptionHandler | ( | const std::unique_ptr< Logging::FMTLogger > & | logger | ) |
Construct a FMTExceptionHandler with a logger.
| [in] | logger | the logger to use. |
|
staticprotected |
Construct a FMTException from an exception type, a section, a message and the location where it occurred.
| [in] | p_exception | the exception type. |
| [in] | p_section | the section in which the exception occurred. |
| [in] | p_message | the message of the exception. |
| [in] | p_method | the method where the exception occurred. |
| [in] | p_file | the file where the exception occurred. |
| [in] | p_line | the line where the exception occurred. |
|
protected |
The guts of logging exceptions.
| [in] | texception | the exception to log. |
| [in] | level | the nesting level. |
|
protected |
The guts of printExceptions.
| [in] | text | the message of the exception. |
| [in] | method | the method where the exception occurred. |
| [in] | line | the line where the exception occurred. |
| [in] | fil | the file where the exception occurred. |
| [in,out] | levelreference | the nesting level reference. |
| [in] | lsection | the section in which the exception occurred. |
| [in] | logfirstlevel | if true logs the first level. |
|
protected |
Return true if we are on the main thread.
|
protected |
Return true if this thread has thrown.
|
protected |
Return true if the thread is registered.
|
protected |
Return true if an exception has been thrown on a thread.
|
protected |
Return true if nested exceptions are used and the exception is a function error that must be rethrown.
|
protected |
Register a worker thread so the handler knows it is dealing with a slave thread and not the main one.
|
protected |
Update the status of the handler of the last exception type thrown and modify if it as to be ignored.
| [in] | p_exception | the new exception |
|
protected |
update the warning count and print if max not reached
| [in] | p_warning | the famous warning |
| void Exception::FMTExceptionHandler::checkSignals | ( | ) | const |
|
pure virtual |
clone the FMTExceptionHandler
Implemented in Exception::FMTDebugExceptionHandler, Exception::FMTDefaultExceptionHandler, Exception::FMTExcelExceptionHandler, Exception::FMTFreeExceptionHandler, and Exception::FMTQuietExceptionHandler.
| void Exception::FMTExceptionHandler::disableNestedExceptions | ( | ) |
Disable the throwing of nested exceptions.
| void Exception::FMTExceptionHandler::enableNestedExceptions | ( | ) |
Enable the throwing of nested exceptions.
|
virtual |
Return a copy of the abstract handler for use in the FMTCPLErrorHandler function when using GDAL.
Reimplemented in Exception::FMTDebugExceptionHandler, Exception::FMTDefaultExceptionHandler, Exception::FMTFreeExceptionHandler, and Exception::FMTQuietExceptionHandler.
|
static |
get descriptions of the potential errors
| [in] | p_french | true you get it in french |
| [in] | p_exception | excpetion type return string description |
|
static |
gives you a vector of error you can safely turn into warning using setErrorsToWarning return a vector of FMTexc
|
virtual |
Callback called by GDAL for handling GDAL errors thrown.
| [in] | eErrClass | the error class. |
| [in] | nError | the error number. |
| [in] | pszErrorMsg | the error message. |
Reimplemented in Exception::FMTDebugExceptionHandler, Exception::FMTDefaultExceptionHandler, Exception::FMTFreeExceptionHandler, and Exception::FMTQuietExceptionHandler.
| FMTExceptionHandler & Exception::FMTExceptionHandler::operator= | ( | const FMTExceptionHandler & | rhs | ) |
Default copy assignment operator for FMTExceptionHandler.
| [in] | rhs | the FMTExceptionHandler to copy. |
| void Exception::FMTExceptionHandler::passInLogger | ( | const std::unique_ptr< Logging::FMTLogger > & | logger | ) |
Pass a logger to the shared pointer of the handler for sharing.
| [in] | logger | the logger to pass in. |
|
virtual |
Print all nested exceptions starting with the first provided.
| [in] | text | the message of the exception. |
| [in] | method | the method where the exception occurred. |
| [in] | line | the line where the exception occurred. |
| [in] | fil | the file where the exception occurred. |
| [in] | lsection | the section in which the exception occurred. |
|
virtual |
Throw a FMTException based on the exception type, section, message and source location. Also used for warnings.
| [in] | lexception | the exception type. |
| [in] | text | the message of the exception. |
| [in] | method | the method where the exception occurred. |
| [in] | line | the line where the exception occurred. |
| [in] | file | the file where the exception occurred. |
| [in] | lsection | the section in which the exception occurred. |
| [in] | throwit | if true throws the exception. |
Reimplemented in Exception::FMTExcelExceptionHandler, Exception::FMTDebugExceptionHandler, Exception::FMTDefaultExceptionHandler, Exception::FMTFreeExceptionHandler, and Exception::FMTQuietExceptionHandler.
|
virtual |
Raise an exception from a catch body, determining if the exception is unhandled.
| [in] | text | the message of the exception. |
| [in] | method | the method where the exception occurred. |
| [in] | line | the line where the exception occurred. |
| [in] | file | the file where the exception occurred. |
| [in] | lsection | the section in which the exception occurred. |
| 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.
| [in] | text | the message of the exception. |
| [in] | method | the method where the exception occurred. |
| [in] | line | the line where the exception occurred. |
| [in] | file | the file where the exception occurred. |
| [in] | lsection | the section in which the exception occurred. |
| void Exception::FMTExceptionHandler::reRaiseIfThreadCrash | ( | ) |
Re-raise a multithread error if an exception was raised by any thread.
| void Exception::FMTExceptionHandler::setErrorsToWarnings | ( | const std::vector< Exception::FMTexc > & | errors | ) |
Set a list of errors to be cast to warnings.
| [in] | errors | the errors to treat as warnings. |
| void Exception::FMTExceptionHandler::setMaxWarningsBeforeSilenced | ( | const size_t & | maxwarningcount | ) |
Setter for the maximum number of warnings before they are silenced.
| [in] | maxwarningcount | the maximum warning count. |
| void Exception::FMTExceptionHandler::throwNested | ( | const std::exception & | texception, |
| int & | level, | ||
| bool | rethrow = true |
||
| ) |
Throw a nested exception.
| [in] | texception | the exception to nest. |
| [in,out] | level | the nesting level. |
| [in] | rethrow | if true rethrows the exception. |
|
friend |
Serialize function used for serialization to do multiprocessing across multiple cpus (pickle in Python).
| Archive | the archive type. |
| [in,out] | ar | the archive to serialize to or from. |
| [in] | version | the serialization version. |
|
protected |
Keeps count of the number of error thrown.
|
protected |
This is the type of the last FMTException thrown by the FMTExceptionHandler.
|
protected |
pointer to the logger used to print the warning / error.
|
staticprotected |
The thread id of the crashed thread.
|
protected |
If an error is in this list it's going to processed like a warning.
|
staticprotected |
Main thread id.
|
protected |
Number of time that the handler throw a certain warning before stop throwing it.
|
mutableprotected |
Mutex for multi-threading.
|
protected |
This is the level of the last FMTException thrown by the FMTExceptionHandler.
|
protected |
The exception throwed by the faulty thread...
|
protected |
If usenested = true then the handler will throw nested exceptions.