1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
6 #include "base/i2-base.hpp"
7 #include "base/string.hpp"
8 #include "base/stacktrace.hpp"
9 #include "base/context.hpp"
10 #include "base/debuginfo.hpp"
11 #include "base/dictionary.hpp"
12 #include "base/configobject.hpp"
13 #include <boost/exception/errinfo_api_function.hpp>
14 #include <boost/exception/errinfo_errno.hpp>
15 #include <boost/exception/errinfo_file_name.hpp>
16 #include <boost/exception/diagnostic_information.hpp>
17 #include <boost/exception_ptr.hpp>
20 # include <boost/algorithm/string/trim.hpp>
26 class user_error : virtual public std::exception, virtual public boost::exception
32 class ScriptError : virtual public user_error
35 ScriptError(String message);
36 ScriptError(String message, DebugInfo di, bool incompleteExpr = false);
37 ~ScriptError() throw() = default;
39 const char *what(void) const throw() final;
41 DebugInfo GetDebugInfo() const;
42 bool IsIncompleteExpression() const;
44 bool IsHandledByDebugger() const;
45 void SetHandledByDebugger(bool handled);
49 DebugInfo m_DebugInfo;
50 bool m_IncompleteExpr;
51 bool m_HandledByDebugger;
57 class ValidationError : virtual public user_error
60 ValidationError(const ConfigObject::Ptr& object, const std::vector<String>& attributePath, const String& message);
61 ~ValidationError() throw() override;
63 const char *what() const throw() override;
65 ConfigObject::Ptr GetObject() const;
66 std::vector<String> GetAttributePath() const;
67 String GetMessage() const;
69 void SetDebugHint(const Dictionary::Ptr& dhint);
70 Dictionary::Ptr GetDebugHint() const;
73 ConfigObject::Ptr m_Object;
74 std::vector<String> m_AttributePath;
77 Dictionary::Ptr m_DebugHint;
80 StackTrace *GetLastExceptionStack();
81 void SetLastExceptionStack(const StackTrace& trace);
83 ContextTrace *GetLastExceptionContext();
84 void SetLastExceptionContext(const ContextTrace& context);
86 void RethrowUncaughtException();
88 typedef boost::error_info<StackTrace, StackTrace> StackTraceErrorInfo;
90 std::string to_string(const StackTraceErrorInfo&);
92 typedef boost::error_info<ContextTrace, ContextTrace> ContextTraceErrorInfo;
94 std::string to_string(const ContextTraceErrorInfo& e);
96 String DiagnosticInformation(const std::exception& ex, bool verbose = true, StackTrace *stack = nullptr, ContextTrace *context = nullptr);
97 String DiagnosticInformation(const boost::exception_ptr& eptr, bool verbose = true);
99 class posix_error : virtual public std::exception, virtual public boost::exception {
101 ~posix_error() throw() override;
103 const char *what(void) const throw() final;
106 mutable char *m_Message{nullptr};
110 class win32_error : virtual public std::exception, virtual public boost::exception { };
112 struct errinfo_win32_error_;
113 typedef boost::error_info<struct errinfo_win32_error_, int> errinfo_win32_error;
115 std::string to_string(const errinfo_win32_error& e);
118 struct errinfo_getaddrinfo_error_;
119 typedef boost::error_info<struct errinfo_getaddrinfo_error_, int> errinfo_getaddrinfo_error;
121 std::string to_string(const errinfo_getaddrinfo_error& e);
123 struct errinfo_message_;
124 typedef boost::error_info<struct errinfo_message_, std::string> errinfo_message;
128 #endif /* EXCEPTION_H */