2012-05-10 12:06:41 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2015-01-22 12:00:23 +01:00
|
|
|
* Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org) *
|
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-16 21:18:53 +01:00
|
|
|
#include <sstream>
|
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>
|
|
|
|
#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
|
|
|
|
{
|
|
|
|
|
2014-10-01 17:01:47 +02:00
|
|
|
class I2_BASE_API user_error : virtual public std::exception, virtual public boost::exception
|
|
|
|
{ };
|
2014-03-22 08:38:46 +01:00
|
|
|
|
2014-12-18 15:11:57 +01:00
|
|
|
/*
|
|
|
|
* @ingroup base
|
|
|
|
*/
|
|
|
|
class I2_BASE_API ScriptError : virtual public user_error
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ScriptError(const String& message);
|
2015-02-10 13:27:02 +01:00
|
|
|
ScriptError(const String& message, const DebugInfo& di, bool incompleteExpr = false);
|
2014-12-18 15:11:57 +01:00
|
|
|
~ScriptError(void) throw();
|
|
|
|
|
2015-08-18 09:12:49 +02:00
|
|
|
virtual const char *what(void) const throw() override;
|
2014-12-18 15:11:57 +01:00
|
|
|
|
|
|
|
DebugInfo GetDebugInfo(void) const;
|
2015-02-10 13:27:02 +01:00
|
|
|
bool IsIncompleteExpression(void) const;
|
2014-12-18 15:11:57 +01:00
|
|
|
|
2015-11-05 14:29:45 +01:00
|
|
|
bool IsHandledByDebugger(void) const;
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
class I2_BASE_API ValidationError : virtual public user_error
|
|
|
|
{
|
|
|
|
public:
|
2015-08-15 20:28:05 +02:00
|
|
|
ValidationError(const ConfigObject::Ptr& object, const std::vector<String>& attributePath, const String& message);
|
2014-11-30 23:32:13 +01:00
|
|
|
~ValidationError(void) throw();
|
|
|
|
|
2015-08-18 09:12:49 +02:00
|
|
|
virtual const char *what(void) const throw() override;
|
2014-11-30 23:32:13 +01:00
|
|
|
|
2015-08-15 20:28:05 +02:00
|
|
|
ConfigObject::Ptr GetObject(void) const;
|
2014-11-30 23:32:13 +01:00
|
|
|
std::vector<String> GetAttributePath(void) const;
|
|
|
|
String GetMessage(void) const;
|
|
|
|
|
|
|
|
void SetDebugHint(const Dictionary::Ptr& dhint);
|
|
|
|
Dictionary::Ptr GetDebugHint(void) const;
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2013-11-20 21:55:14 +01:00
|
|
|
I2_BASE_API StackTrace *GetLastExceptionStack(void);
|
|
|
|
I2_BASE_API void SetLastExceptionStack(const StackTrace& trace);
|
|
|
|
|
2013-11-19 07:49:41 +01:00
|
|
|
I2_BASE_API ContextTrace *GetLastExceptionContext(void);
|
|
|
|
I2_BASE_API void SetLastExceptionContext(const ContextTrace& context);
|
|
|
|
|
2014-04-14 03:02:33 +02:00
|
|
|
I2_BASE_API void RethrowUncaughtException(void);
|
|
|
|
|
2013-11-20 21:55:14 +01:00
|
|
|
typedef boost::error_info<StackTrace, StackTrace> StackTraceErrorInfo;
|
|
|
|
|
2014-12-20 15:29:04 +01:00
|
|
|
inline std::string to_string(const StackTraceErrorInfo& e)
|
2012-04-03 13:01:00 +02:00
|
|
|
{
|
2014-12-20 15:29:04 +01:00
|
|
|
return "";
|
|
|
|
}
|
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
|
|
|
|
2014-12-20 15:29:04 +01:00
|
|
|
inline std::string to_string(const ContextTraceErrorInfo& e)
|
|
|
|
{
|
|
|
|
std::ostringstream msgbuf;
|
|
|
|
msgbuf << "[Context] = " << e.value();
|
|
|
|
return msgbuf.str();
|
|
|
|
}
|
2014-03-29 23:02:55 +01:00
|
|
|
|
2014-12-20 15:29:04 +01:00
|
|
|
I2_BASE_API String DiagnosticInformation(const std::exception& ex, bool verbose = true, StackTrace *stack = NULL, ContextTrace *context = NULL);
|
|
|
|
I2_BASE_API String DiagnosticInformation(boost::exception_ptr eptr, bool verbose = true);
|
2013-11-19 07:49:41 +01:00
|
|
|
|
2014-12-20 15:29:04 +01:00
|
|
|
class I2_BASE_API posix_error : virtual public std::exception, virtual public boost::exception {
|
|
|
|
public:
|
|
|
|
posix_error(void);
|
|
|
|
virtual ~posix_error(void) throw();
|
2013-11-20 21:55:14 +01:00
|
|
|
|
2015-08-18 09:12:49 +02:00
|
|
|
virtual const char *what(void) const throw() override;
|
2013-03-07 19:44:39 +01:00
|
|
|
|
2014-12-20 15:29:04 +01:00
|
|
|
private:
|
|
|
|
mutable char *m_Message;
|
|
|
|
};
|
2012-05-18 22:21:28 +02:00
|
|
|
|
2012-04-22 16:45:31 +02:00
|
|
|
#ifdef _WIN32
|
2013-03-11 14:03:01 +01:00
|
|
|
class I2_BASE_API win32_error : virtual public std::exception, virtual public boost::exception { };
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
inline std::string to_string(const errinfo_win32_error& e)
|
2012-04-22 16:45:31 +02:00
|
|
|
{
|
2014-12-20 15:29:04 +01:00
|
|
|
return "[errinfo_win32_error] = " + Utility::FormatErrorNumber(e.value()) + "\n";
|
2013-03-11 13:45:08 +01:00
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
inline std::string to_string(const errinfo_getaddrinfo_error& e)
|
|
|
|
{
|
2015-08-29 01:16:16 +02:00
|
|
|
String msg;
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
msg = gai_strerrorA(e.value());
|
|
|
|
#else /* _WIN32 */
|
|
|
|
msg = gai_strerror(e.value());
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
|
|
|
return "[errinfo_getaddrinfo_error] = " + String(msg) + "\n";
|
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 */
|