FMT 0.9.8
Forest management tools for forest planning
Loading...
Searching...
No Matches
FMTexceptionhandler.hpp
Go to the documentation of this file.
1/*
2Copyright (c) 2019 Gouvernement du Québec
3
4SPDX-License-Identifier: LiLiQ-R-1.1
5License-Filename: LICENSES/EN/LiLiQ-R11unicode.txt
6*/
7
8#ifndef FMTexceptionhandler_H_INCLUDED
9#define FMTexceptionhandler_H_INCLUDED
10
11
12#include "FMTlogger.hpp"
13#include <unordered_map>
14#include <boost/serialization/serialization.hpp>
15#include <boost/serialization/nvp.hpp>
16#include <boost/serialization/export.hpp>
17#include <memory>
18#include <set>
19
20#include <boost/thread.hpp>
21
22namespace Exception
23{
24 class FMTexception;
25 // DocString: FMTexceptionhandler
32 {
33 // DocString: FMTexceptionhandler::serialize
37 friend class boost::serialization::access;
38 template<class Archive>
39 void serialize(Archive& ar, const unsigned int version)
40 {
41 ar & BOOST_SERIALIZATION_NVP(_level);
42 ar & BOOST_SERIALIZATION_NVP(_exception);
43 ar & BOOST_SERIALIZATION_NVP(_errorcount);
44 ar & BOOST_SERIALIZATION_NVP(_warningcount);
45 ar & BOOST_SERIALIZATION_NVP(_logger);
46 ar & BOOST_SERIALIZATION_NVP(usenestedexceptions);
47 }
48 protected:
49 // DocString: FMTexceptionhandler::_level
52 // DocString: FMTexceptionhandler::_exception
55 // DocString: FMTexceptionhandler::_errorcount
58 // DocString: FMTexceptionhandler::_warningcount
61 // DocString: FMTexceptionhandler::maxwarningsbeforesilenced
64 // DocString: FMTexceptionhandler::_logger
66 std::shared_ptr<Logging::FMTlogger>_logger;
67 // DocString: FMTexceptionhandler::usenestedexceptions
70 // DocString: FMTexceptionhandler::mtx
72 //mutable std::recursive_mutex mtx;
73 mutable boost::recursive_mutex mtx;
74 // DocString: FMTexceptionhandler::errorstowarnings
76 std::vector<Exception::FMTexc>errorstowarnings;
77 // DocString: FMTexceptionhandler::registred_threads
79 std::set<boost::thread::id> registered_threads;
80 // DocString: FMTexceptionhandler::mainthreadid
82 static boost::thread::id mainthreadid;
83 // DocString: FMTexceptionhandler::crashedthreadid
85 static boost::thread::id crashedthreadid;
86 // DocString: FMTexceptionhandler::threadcrashexceptions
88 std::exception_ptr threadcrashexception;
89 // DocString: FMTexceptionhandler::updatestatus
94 std::string updatestatus(const FMTexc lexception, const std::string message);
95 // DocString: FMTexceptionhandler::needtorethrow
99 bool needtorethrow() const;
100 // DocString: FMTexceptionhandler::ismainthread()
104 bool ismainthread() const;
105 // DocString: FMTexceptionhandler::isthrowedonthread()
109 bool isthrowedonthread() const;
110 // DocString: FMTexceptionhandler::isthisthreadthrowed()
115 // DocString: FMTexceptionhandler::registerthread
121 // DocString: FMTexceptionhandler::isregistered
125 bool isthreadregistered() const;
126 // DocString: FMTexceptionhandler::gutsofprintexceptions
130 void gutsofprintexceptions(std::string text,
131 const std::string& method, const int& line, const std::string& fil,
132 int& levelreference,Core::FMTsection lsection = Core::FMTsection::Empty,bool logfirstlevel = true);
133 // DocString: FMTexceptionhandler::gutsofexceptionlog
137 void gutsofexceptionlog(const std::exception& texception,const int& level);
138 public:
139 // DocString: FMTexceptionhandler::_specificwarningcount
141 std::unordered_map<int,size_t> _specificwarningcount;
142 // DocString: checksignals()
146 void checksignals() const;
147 // DocString: FMTexceptionhandler()
152 // DocString: ~FMTexceptionhandler()
156 virtual ~FMTexceptionhandler()=default;
157 // DocString: FMTexceptionhandler(const FMTexceptionhandler&)
162 // DocString: FMTexceptionhandler(const std::shared_ptr<Logging::FMTlogger>&)
166 FMTexceptionhandler(const std::shared_ptr<Logging::FMTlogger>& logger);
167 // DocString: FMTexceptionhandler::passinlogger
171 void passinlogger(const std::shared_ptr<Logging::FMTlogger>& logger);
172
173 // DocString: FMTexceptionhandler::getCPLdata
179 #if defined FMTWITHGDAL
180 // DocString: FMTexceptionhandler::handelCPLerror
184 virtual void handelCPLerror(int eErrClass, int nError, const char * pszErrorMsg);
185 #endif
186 // DocString: FMTexceptionhandler::operator=
190 FMTexceptionhandler& operator = (const FMTexceptionhandler& rhs);
191 // DocString: FMTexceptionhandler::throw_nested
195 void throw_nested(const std::exception& texception, int& level,bool rethrow=true);
196 // DocString: FMTexceptionhandler::printexceptions
200 virtual void printexceptions(std::string text,
201 const std::string& method, const int& line, const std::string& fil,
203 // DocString: FMTexceptionhandler::raise
208 virtual FMTexception raise(FMTexc lexception,std::string text,
209 const std::string& method, const int& line, const std::string& file,
210 Core::FMTsection lsection = Core::FMTsection::Empty ,bool throwit = true);
211 // DocString: FMTexceptionhandler::raisefromcatch
215 virtual FMTexception raisefromcatch(std::string text,
216 const std::string& method, const int& line, const std::string& file,
218 // DocString: FMTexceptionhandler::raisefromthreadcatch
224 void raisefromthreadcatch(std::string text,
225 const std::string& method, const int& line, const std::string& file,
227 // DocString: FMTexceptionhandler::reraiseifthreadcrash
233 // DocString: FMTexceptionhandler::enablenestedexceptions
238 // DocString: FMTexceptionhandler::disablenestedexceptions
243 // DocString: seterrorstowarnings()
248 void seterrorstowarnings(const std::vector<Exception::FMTexc>& errors);
249 // DocString: setmaxwarningsbeforesilenced()
253 void setmaxwarningsbeforesilenced(const size_t& maxwarningcount);
254 };
255
256}
257
258BOOST_CLASS_EXPORT_KEY(Exception::FMTexceptionhandler)
259
260#endif
#define FMTEXPORT
Definition: FMTutility.hpp:92
Definition: FMTexception.hpp:134
Definition: FMTexceptionhandler.hpp:32
FMTexc _exception
This is the type of the last FMTexception thrown by the FMTexceptionhandler.
Definition: FMTexceptionhandler.hpp:54
void seterrorstowarnings(const std::vector< Exception::FMTexc > &errors)
std::string updatestatus(const FMTexc lexception, const std::string message)
void setmaxwarningsbeforesilenced(const size_t &maxwarningcount)
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)
size_t maxwarningsbeforesilenced
Number of time that the handler throw a certain warning before stop throwing it.
Definition: FMTexceptionhandler.hpp:63
std::vector< Exception::FMTexc > errorstowarnings
If an error is in this list it's going to processed like a warning.
Definition: FMTexceptionhandler.hpp:76
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)
FMTlev _level
This is the level of the last FMTexception thrown by the FMTexceptionhandler.
Definition: FMTexceptionhandler.hpp:51
void passinlogger(const std::shared_ptr< Logging::FMTlogger > &logger)
int _warningcount
Keeps count of the number of warning thrown.
Definition: FMTexceptionhandler.hpp:60
void gutsofexceptionlog(const std::exception &texception, const int &level)
static boost::thread::id mainthreadid
Main thread id.
Definition: FMTexceptionhandler.hpp:82
virtual void handelCPLerror(int eErrClass, int nError, const char *pszErrorMsg)
std::exception_ptr threadcrashexception
The exception throwed by the faulty thread...
Definition: FMTexceptionhandler.hpp:88
boost::recursive_mutex mtx
Mutex for multi-threading.
Definition: FMTexceptionhandler.hpp:73
virtual FMTexception raisefromcatch(std::string text, const std::string &method, const int &line, const std::string &file, Core::FMTsection lsection=Core::FMTsection::Empty)
void throw_nested(const std::exception &texception, int &level, bool rethrow=true)
FMTexceptionhandler(const FMTexceptionhandler &rhs)
std::set< boost::thread::id > registered_threads
This is the level of the last FMTexception thrown by the FMTexceptionhandler.
Definition: FMTexceptionhandler.hpp:79
FMTexceptionhandler(const std::shared_ptr< Logging::FMTlogger > &logger)
std::shared_ptr< Logging::FMTlogger > _logger
pointer to the logger used to print the warning / error.
Definition: FMTexceptionhandler.hpp:66
int _errorcount
Keeps count of the number of error thrown.
Definition: FMTexceptionhandler.hpp:57
virtual ~FMTexceptionhandler()=default
virtual void printexceptions(std::string text, const std::string &method, const int &line, const std::string &fil, Core::FMTsection lsection=Core::FMTsection::Empty)
virtual FMTexceptionhandler * getCPLdata()
static boost::thread::id crashedthreadid
The thread id of the crashed thread.
Definition: FMTexceptionhandler.hpp:85
bool usenestedexceptions
If usenested = true then the handler will throw nested exceptions.
Definition: FMTexceptionhandler.hpp:69
void raisefromthreadcatch(std::string text, const std::string &method, const int &line, const std::string &file, Core::FMTsection lsection=Core::FMTsection::Empty)
std::unordered_map< int, size_t > _specificwarningcount
Keeps count of the number of each type of warning thrown.
Definition: FMTexceptionhandler.hpp:141
FMTsection
Definition: FMTutility.hpp:23
@ Empty
Definition: FMTutility.hpp:35
Namespace for exceptions and exceptions handling (warnings and errors) thrown by FMT and all exceptio...
Definition: FMTcplhandler.hpp:16
FMTexc
Definition: FMTexception.hpp:42
FMTlev
Definition: FMTexception.hpp:29