8#ifndef FMTexceptionhandler_Hm_included
9#define FMTexceptionhandler_Hm_included
13#include <unordered_map>
14#include <boost/serialization/serialization.hpp>
15#include <boost/serialization/nvp.hpp>
16#include <boost/serialization/export.hpp>
19#include <boost/thread.hpp>
68 void passInLogger(
const std::unique_ptr<Logging::FMTLogger>& logger);
76 #if defined FMTWITHGDAL
84 virtual void handelCplError(
int eErrClass,
int nError,
const char* pszErrorMsg);
100 void throwNested(
const std::exception& texception,
int& level,
bool rethrow =
true);
111 const std::string& method,
const int& line,
const std::string& fil,
126 const std::string& method,
const int& line,
const std::string& file,
139 const std::string& method,
const int& line,
const std::string& file,
151 const std::string& method,
const int& line,
const std::string& file,
185 virtual std::unique_ptr <FMTExceptionHandler>
clone()
const = 0;
192 static void translateStructuralWIN32Exceptions(
unsigned int p_u, EXCEPTION_POINTERS*);
227 mutable boost::recursive_mutex
m_mtx;
260 const std::string& p_method,
const std::string& p_file,
int p_line);
308 const std::string& method,
const int& line,
const std::string& fil,
331 friend class boost::serialization::access;
332 template<
class Archive>
333 void serialize(Archive& ar,
const unsigned int version)
335 ar& BOOST_SERIALIZATION_NVP(_exception);
336 ar& BOOST_SERIALIZATION_NVP(_logger);
337 ar& BOOST_SERIALIZATION_NVP(m_usenestedexceptions);
346 std::unordered_map<FMTexc, size_t> m_specificwarningcount;
#define FMTEXPORT
Definition: FMTutility.h:125
Base class used to handle errors thrown in FMT.
Definition: FMTExceptionHandler.h:34
static boost::thread::id m_mainthreadid
Main thread id.
Definition: FMTExceptionHandler.h:236
std::vector< Exception::FMTexc > m_errorstowarnings
If an error is in this list it's going to processed like a warning.
Definition: FMTExceptionHandler.h:230
static boost::thread::id m_crashedthreadid
The thread id of the crashed thread.
Definition: FMTExceptionHandler.h:239
Logging::FMTLogger * _logger
pointer to the logger used to print the warning / error.
Definition: FMTExceptionHandler.h:220
FMTExceptionHandler()
Default constructor for FMTExceptionHandler.
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 setErrorsToWarnings(const std::vector< Exception::FMTexc > &errors)
Set a list of errors to be cast to warnings.
std::set< boost::thread::id > m_registered_threads
This is the level of the last FMTException thrown by the FMTExceptionHandler.
Definition: FMTExceptionHandler.h:233
void _registerWorkerThread()
Register a worker thread so the handler knows it is dealing with a slave thread and not the main one.
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....
static std::vector< FMTexc > getErrorsToIgnore()
gives you a vector of error you can safely turn into warning using setErrorsToWarning return a vector...
boost::recursive_mutex m_mtx
Mutex for multi-threading.
Definition: FMTExceptionHandler.h:227
void checkSignals() const
Check signals in R and Python if on the main thread.
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 wi...
void _gutsOfExceptionLog(const std::exception &texception, const int &level)
The guts of logging exceptions.
void setMaxWarningsBeforeSilenced(const size_t &maxwarningcount)
Setter for the maximum number of warnings before they are silenced.
bool _isThreadRegistered() const
Return true if the thread is registered.
FMTExceptionHandler(const std::unique_ptr< Logging::FMTLogger > &logger)
Construct a FMTExceptionHandler with a logger.
void reRaiseIfThreadCrash()
Re-raise a multithread error if an exception was raised by any thread.
void disableNestedExceptions()
Disable the throwing of nested exceptions.
bool m_usenestedexceptions
If usenested = true then the handler will throw nested exceptions.
Definition: FMTExceptionHandler.h:223
bool _isThisThreadThrowed() const
Return true if this thread has thrown.
void _updateWarningCount(const FMTException &p_warning)
update the warning count and print if max not reached
virtual FMTExceptionHandler * getCplData()
Return a copy of the abstract handler for use in the FMTCPLErrorHandler function when using GDAL.
FMTExceptionHandler(const FMTExceptionHandler &rhs)
Copy constructor for FMTExceptionHandler.
int _errorcount
Keeps count of the number of error thrown.
Definition: FMTExceptionHandler.h:214
static std::string getErrorDescription(bool p_french, FMTexc p_type)
get descriptions of the potential errors
virtual void handelCplError(int eErrClass, int nError, const char *pszErrorMsg)
Callback called by GDAL for handling GDAL errors thrown.
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.
std::exception_ptr m_threadcrashexception
The exception throwed by the faulty thread...
Definition: FMTExceptionHandler.h:242
void throwNested(const std::exception &texception, int &level, bool rethrow=true)
Throw a nested exception.
void enableNestedExceptions()
Enable the throwing of nested exceptions.
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.
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.
void passInLogger(const std::unique_ptr< Logging::FMTLogger > &logger)
Pass a logger to the shared pointer of the handler for sharing.
virtual std::unique_ptr< FMTExceptionHandler > clone() const =0
clone the FMTExceptionHandler
size_t m_maxwarningsbeforesilenced
Number of time that the handler throw a certain warning before stop throwing it.
Definition: FMTExceptionHandler.h:217
virtual ~FMTExceptionHandler()=default
Default virtual destructor for FMTExceptionHandler.
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 occur...
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.
FMTexc _exception
This is the type of the last FMTException thrown by the FMTExceptionHandler.
Definition: FMTExceptionHandler.h:211
bool _isThrowedOnThread() const
Return true if an exception has been thrown on a thread.
Base exception class for FMT holding the type, section and message of a given exception.
Definition: FMTException.h:140
RAII helper that installs a structured exception translator for its scope on MSVC.
Definition: FMTScopedSeTranslator.h:26
Base class handling the level of information printed by FMT.
Definition: FMTLogger.h:37
FMTsection
Enumerator describing the sections of a Woodstock model.
Definition: FMTutility.h:32
@ Empty
Definition: FMTutility.h:44
Namespace for exceptions and exceptions handling (warnings and errors) thrown by FMT and all exceptio...
Definition: FMTAggregateRedefinition.h:11
FMTexc
Enumerator describing the exceptions thrown by FMT.
Definition: FMTException.h:45