2012-05-10 12:06:41 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2018-10-18 09:27:04 +02:00
|
|
|
* Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com/) *
|
2012-05-10 12:06:41 +02:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
2012-05-11 13:33:57 +02:00
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
2012-05-10 12:06:41 +02:00
|
|
|
******************************************************************************/
|
|
|
|
|
2012-04-03 13:01:00 +02:00
|
|
|
#ifndef EXCEPTION_H
|
|
|
|
#define EXCEPTION_H
|
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "base/i2-base.hpp"
|
2014-10-19 14:48:19 +02:00
|
|
|
#include "base/string.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "base/stacktrace.hpp"
|
|
|
|
#include "base/context.hpp"
|
2014-11-07 09:53:23 +01:00
|
|
|
#include "base/utility.hpp"
|
2014-12-18 15:11:57 +01:00
|
|
|
#include "base/debuginfo.hpp"
|
2014-11-30 23:32:13 +01:00
|
|
|
#include "base/dictionary.hpp"
|
2015-08-15 20:28:05 +02:00
|
|
|
#include "base/configobject.hpp"
|
2013-03-18 17:04:22 +01:00
|
|
|
#include <boost/exception/errinfo_api_function.hpp>
|
|
|
|
#include <boost/exception/errinfo_errno.hpp>
|
|
|
|
#include <boost/exception/errinfo_file_name.hpp>
|
2013-11-20 21:55:14 +01:00
|
|
|
#include <boost/exception/diagnostic_information.hpp>
|
2016-08-31 13:43:14 +02:00
|
|
|
#include <boost/exception_ptr.hpp>
|
2013-03-15 18:21:29 +01:00
|
|
|
|
2013-03-16 21:18:53 +01:00
|
|
|
#ifdef _WIN32
|
|
|
|
# include <boost/algorithm/string/trim.hpp>
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
2012-04-03 13:01:00 +02:00
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
2017-12-31 07:22:16 +01:00
|
|
|
class user_error : virtual public std::exception, virtual public boost::exception
|
2014-10-01 17:01:47 +02:00
|
|
|
{ };
|
2014-03-22 08:38:46 +01:00
|
|
|
|
2014-12-18 15:11:57 +01:00
|
|
|
/*
|
|
|
|
* @ingroup base
|
|
|
|
*/
|
2017-12-31 07:22:16 +01:00
|
|
|
class ScriptError : virtual public user_error
|
2014-12-18 15:11:57 +01:00
|
|
|
{
|
|
|
|
public:
|
2018-01-04 08:54:18 +01:00
|
|
|
ScriptError(String message);
|
|
|
|
ScriptError(String message, DebugInfo di, bool incompleteExpr = false);
|
2018-01-04 09:43:49 +01:00
|
|
|
~ScriptError() throw() = default;
|
2014-12-18 15:11:57 +01:00
|
|
|
|
2018-01-04 05:12:56 +01:00
|
|
|
const char *what(void) const throw() final;
|
2014-12-18 15:11:57 +01:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
DebugInfo GetDebugInfo() const;
|
|
|
|
bool IsIncompleteExpression() const;
|
2014-12-18 15:11:57 +01:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
bool IsHandledByDebugger() const;
|
2015-11-05 14:29:45 +01:00
|
|
|
void SetHandledByDebugger(bool handled);
|
|
|
|
|
2014-12-18 15:11:57 +01:00
|
|
|
private:
|
|
|
|
String m_Message;
|
|
|
|
DebugInfo m_DebugInfo;
|
2015-02-10 13:27:02 +01:00
|
|
|
bool m_IncompleteExpr;
|
2015-11-05 14:29:45 +01:00
|
|
|
bool m_HandledByDebugger;
|
2014-12-18 15:11:57 +01:00
|
|
|
};
|
|
|
|
|
2014-11-30 23:32:13 +01:00
|
|
|
/*
|
|
|
|
* @ingroup base
|
|
|
|
*/
|
2017-12-31 07:22:16 +01:00
|
|
|
class ValidationError : virtual public user_error
|
2014-11-30 23:32:13 +01:00
|
|
|
{
|
|
|
|
public:
|
2015-08-15 20:28:05 +02:00
|
|
|
ValidationError(const ConfigObject::Ptr& object, const std::vector<String>& attributePath, const String& message);
|
2018-01-04 05:12:56 +01:00
|
|
|
~ValidationError() throw() override;
|
2014-11-30 23:32:13 +01:00
|
|
|
|
2018-01-04 05:12:56 +01:00
|
|
|
const char *what() const throw() override;
|
2014-11-30 23:32:13 +01:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
ConfigObject::Ptr GetObject() const;
|
|
|
|
std::vector<String> GetAttributePath() const;
|
|
|
|
String GetMessage() const;
|
2014-11-30 23:32:13 +01:00
|
|
|
|
|
|
|
void SetDebugHint(const Dictionary::Ptr& dhint);
|
2018-01-04 04:25:35 +01:00
|
|
|
Dictionary::Ptr GetDebugHint() const;
|
2014-11-30 23:32:13 +01:00
|
|
|
|
|
|
|
private:
|
2015-08-15 20:28:05 +02:00
|
|
|
ConfigObject::Ptr m_Object;
|
2014-11-30 23:32:13 +01:00
|
|
|
std::vector<String> m_AttributePath;
|
|
|
|
String m_Message;
|
|
|
|
String m_What;
|
|
|
|
Dictionary::Ptr m_DebugHint;
|
|
|
|
};
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
StackTrace *GetLastExceptionStack();
|
2017-12-31 07:22:16 +01:00
|
|
|
void SetLastExceptionStack(const StackTrace& trace);
|
2013-11-20 21:55:14 +01:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
ContextTrace *GetLastExceptionContext();
|
2017-12-31 07:22:16 +01:00
|
|
|
void SetLastExceptionContext(const ContextTrace& context);
|
2013-11-19 07:49:41 +01:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void RethrowUncaughtException();
|
2014-04-14 03:02:33 +02:00
|
|
|
|
2013-11-20 21:55:14 +01:00
|
|
|
typedef boost::error_info<StackTrace, StackTrace> StackTraceErrorInfo;
|
|
|
|
|
2018-01-04 10:36:35 +01:00
|
|
|
std::string to_string(const StackTraceErrorInfo&);
|
2013-11-20 21:55:14 +01:00
|
|
|
|
2014-12-20 15:29:04 +01:00
|
|
|
typedef boost::error_info<ContextTrace, ContextTrace> ContextTraceErrorInfo;
|
2013-11-19 07:49:41 +01:00
|
|
|
|
2018-01-04 10:36:35 +01:00
|
|
|
std::string to_string(const ContextTraceErrorInfo& e);
|
2014-03-29 23:02:55 +01:00
|
|
|
|
2017-12-31 07:22:16 +01:00
|
|
|
String DiagnosticInformation(const std::exception& ex, bool verbose = true, StackTrace *stack = nullptr, ContextTrace *context = nullptr);
|
2018-01-04 08:54:18 +01:00
|
|
|
String DiagnosticInformation(const boost::exception_ptr& eptr, bool verbose = true);
|
2013-11-19 07:49:41 +01:00
|
|
|
|
2017-12-31 07:22:16 +01:00
|
|
|
class posix_error : virtual public std::exception, virtual public boost::exception {
|
2014-12-20 15:29:04 +01:00
|
|
|
public:
|
2018-01-04 05:12:56 +01:00
|
|
|
~posix_error() throw() override;
|
2013-11-20 21:55:14 +01:00
|
|
|
|
2018-01-04 05:12:56 +01:00
|
|
|
const char *what(void) const throw() final;
|
2013-03-07 19:44:39 +01:00
|
|
|
|
2014-12-20 15:29:04 +01:00
|
|
|
private:
|
2018-01-04 09:43:49 +01:00
|
|
|
mutable char *m_Message{nullptr};
|
2014-12-20 15:29:04 +01:00
|
|
|
};
|
2012-05-18 22:21:28 +02:00
|
|
|
|
2012-04-22 16:45:31 +02:00
|
|
|
#ifdef _WIN32
|
2017-12-31 07:22:16 +01:00
|
|
|
class win32_error : virtual public std::exception, virtual public boost::exception { };
|
2013-03-11 14:03:01 +01:00
|
|
|
|
2013-03-18 17:04:22 +01:00
|
|
|
struct errinfo_win32_error_;
|
2013-03-11 13:45:08 +01:00
|
|
|
typedef boost::error_info<struct errinfo_win32_error_, int> errinfo_win32_error;
|
|
|
|
|
2018-01-04 10:36:35 +01:00
|
|
|
std::string to_string(const errinfo_win32_error& e);
|
2012-04-22 16:45:31 +02:00
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
2013-09-12 07:50:09 +02:00
|
|
|
struct errinfo_getaddrinfo_error_;
|
|
|
|
typedef boost::error_info<struct errinfo_getaddrinfo_error_, int> errinfo_getaddrinfo_error;
|
|
|
|
|
2018-01-04 10:36:35 +01:00
|
|
|
std::string to_string(const errinfo_getaddrinfo_error& e);
|
2013-09-12 07:50:09 +02:00
|
|
|
|
2013-11-05 12:40:25 +01:00
|
|
|
struct errinfo_message_;
|
|
|
|
typedef boost::error_info<struct errinfo_message_, std::string> errinfo_message;
|
|
|
|
|
2012-04-16 16:27:41 +02:00
|
|
|
}
|
|
|
|
|
2012-04-03 13:01:00 +02:00
|
|
|
#endif /* EXCEPTION_H */
|