File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2121
2222namespace mgis {
2323
24+ // ! \brief a simple alias
25+ using ExceptionHandler = void (*)(void );
26+
27+ /* !
28+ * \brief set an exception handler
29+ * \param[in] h: exception handler
30+ *
31+ * \code{.cpp}
32+ * void handler() {
33+ * try {
34+ * throw;
35+ * } catch (std::exception& e) {
36+ * std::cerr << e.what() << '\n';
37+ * } catch (...) {
38+ * std::cerr << "unknown exception thrown";
39+ * }
40+ * std::abort();
41+ * } // end of handler
42+ *
43+ * mgis::setExceptionHandler(handler);
44+ * mgis::raise<std::logic_error>("something went wrong");
45+ * \endcode
46+ */
47+ MGIS_EXPORT void setExceptionHandler (ExceptionHandler);
48+
49+ /* !
50+ * \brief return a registred exception handler, nullptr if none were
51+ * registred.
52+ */
53+ MGIS_EXPORT ExceptionHandler getExceptionHandler ();
54+
2455 /* !
2556 * \brief a small wrapper used to build the exception outside the
2657 * `throw` statement. As most exception's classes constructors may
Original file line number Diff line number Diff line change 1515#ifndef LIB_MGIS_RAISE_IXX
1616#define LIB_MGIS_RAISE_IXX
1717
18+ #include < cstdlib>
19+
1820namespace mgis {
1921
2022 template <typename Exception>
2123 void raise () {
22- Exception e;
23- throw (std::move (e));
24+ const auto h = getExceptionHandler ();
25+ if (h != nullptr ) {
26+ try {
27+ Exception e;
28+ throw (std::move (e));
29+ } catch (...) {
30+ h ();
31+ }
32+ std::abort ();
33+ } else {
34+ Exception e;
35+ throw (std::move (e));
36+ }
2437 } // end of raise
2538
2639 template <typename Exception, typename ... Args>
2740 void raise (Args&&... a) {
28- Exception e (std::forward<Args...>(a...));
29- throw (std::move (e));
41+ const auto h = getExceptionHandler ();
42+ if (h != nullptr ) {
43+ try {
44+ Exception e (std::forward<Args...>(a...));
45+ throw (std::move (e));
46+ } catch (...) {
47+ h ();
48+ }
49+ std::abort ();
50+ } else {
51+ Exception e (std::forward<Args...>(a...));
52+ throw (std::move (e));
53+ }
3054 } // end of raise
3155
3256 template <typename Exception>
Original file line number Diff line number Diff line change 11mgis_library (MFrontGenericInterface SHARED
2- ThreadPool.cxx
2+ Raise.cxx
3+ ThreadPool.cxx
34 ThreadedTaskResult.cxx
45 LibrariesManager.cxx
56 Markdown.cxx
You can’t perform that action at this time.
0 commit comments