2012-05-10 12:06:41 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
|
|
|
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
|
|
|
* *
|
|
|
|
* 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
|
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
2012-04-22 16:45:31 +02:00
|
|
|
/**
|
|
|
|
* Base class for all exceptions.
|
2012-05-18 22:21:28 +02:00
|
|
|
*
|
|
|
|
* @ingroup base
|
2012-04-22 16:45:31 +02:00
|
|
|
*/
|
2012-07-10 15:14:45 +02:00
|
|
|
class I2_BASE_API Exception : public virtual exception
|
2012-04-03 13:01:00 +02:00
|
|
|
{
|
2012-04-22 16:45:31 +02:00
|
|
|
public:
|
2012-05-26 21:30:04 +02:00
|
|
|
Exception(void)
|
|
|
|
: m_Message(), m_Code(0)
|
|
|
|
{ }
|
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
Exception(String message)
|
2012-05-26 21:30:04 +02:00
|
|
|
: m_Message(message), m_Code(0)
|
|
|
|
{ }
|
|
|
|
|
2012-08-02 09:38:08 +02:00
|
|
|
Exception(String message, int code)
|
2012-05-26 21:30:04 +02:00
|
|
|
: m_Message(message), m_Code(code)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor for the Exception class. Must be virtual for RTTI to work.
|
|
|
|
*/
|
|
|
|
virtual ~Exception(void) throw()
|
|
|
|
{ }
|
2012-04-03 13:01:00 +02:00
|
|
|
|
2012-05-26 20:00:03 +02:00
|
|
|
int GetCode(void) const;
|
2012-08-02 09:38:08 +02:00
|
|
|
String GetMessage(void) const;
|
2012-05-17 19:14:03 +02:00
|
|
|
|
|
|
|
virtual const char *what(void) const throw();
|
2012-05-21 23:42:54 +02:00
|
|
|
|
|
|
|
protected:
|
2012-05-26 20:00:03 +02:00
|
|
|
void SetCode(int code);
|
2012-08-02 09:38:08 +02:00
|
|
|
void SetMessage(String message);
|
2012-05-21 23:42:54 +02:00
|
|
|
|
|
|
|
private:
|
2012-08-02 09:38:08 +02:00
|
|
|
String m_Message;
|
2012-05-26 20:00:03 +02:00
|
|
|
int m_Code;
|
2012-04-03 13:01:00 +02:00
|
|
|
};
|
|
|
|
|
2012-05-10 12:06:41 +02:00
|
|
|
#define DEFINE_EXCEPTION_CLASS(klass) \
|
|
|
|
class klass : public Exception \
|
|
|
|
{ \
|
|
|
|
public: \
|
|
|
|
inline klass(void) : Exception() \
|
2012-05-26 21:30:04 +02:00
|
|
|
{ } \
|
2012-05-10 12:06:41 +02:00
|
|
|
\
|
2012-08-02 09:38:08 +02:00
|
|
|
inline klass(String message) \
|
2012-05-10 12:06:41 +02:00
|
|
|
: Exception(message) \
|
2012-05-26 21:30:04 +02:00
|
|
|
{ } \
|
2012-05-10 13:12:25 +02:00
|
|
|
}
|
2012-04-03 13:01:00 +02:00
|
|
|
|
2012-05-18 22:21:28 +02:00
|
|
|
/**
|
|
|
|
* An exception that is thrown when a certain feature
|
|
|
|
* is not implemented.
|
|
|
|
*
|
|
|
|
* @ingroup base
|
|
|
|
*/
|
2012-04-16 16:27:41 +02:00
|
|
|
DEFINE_EXCEPTION_CLASS(NotImplementedException);
|
2012-05-18 22:21:28 +02:00
|
|
|
|
2012-04-22 16:45:31 +02:00
|
|
|
#ifdef _WIN32
|
2012-05-15 10:58:14 +02:00
|
|
|
/**
|
|
|
|
* A Win32 error encapsulated in an exception.
|
2012-09-19 12:32:39 +02:00
|
|
|
*
|
|
|
|
* @ingroup base
|
2012-05-15 10:58:14 +02:00
|
|
|
*/
|
2012-10-17 12:03:07 +02:00
|
|
|
class I2_BASE_API Win32Exception : public Exception
|
2012-04-22 16:45:31 +02:00
|
|
|
{
|
|
|
|
public:
|
2012-05-15 10:58:14 +02:00
|
|
|
/**
|
|
|
|
* Constructor for the Win32Exception class.
|
|
|
|
*
|
|
|
|
* @param message An error message.
|
|
|
|
* @param errorCode A Win32 error code.
|
|
|
|
*/
|
2012-08-02 09:38:08 +02:00
|
|
|
inline Win32Exception(const String& message, int errorCode)
|
2012-05-26 21:30:04 +02:00
|
|
|
: Exception(message + ": " + FormatErrorCode(errorCode), errorCode)
|
|
|
|
{ }
|
2012-04-22 16:45:31 +02:00
|
|
|
|
2012-05-15 10:58:14 +02:00
|
|
|
/**
|
2012-08-02 09:38:08 +02:00
|
|
|
* Returns a String that describes the Win32 error.
|
2012-05-15 10:58:14 +02:00
|
|
|
*
|
|
|
|
* @param code The Win32 error code.
|
|
|
|
* @returns A description of the error.
|
|
|
|
*/
|
2012-08-02 09:38:08 +02:00
|
|
|
static String FormatErrorCode(int code);
|
2012-04-22 16:45:31 +02:00
|
|
|
};
|
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
2012-05-15 10:58:14 +02:00
|
|
|
/**
|
|
|
|
* A Posix error encapsulated in an exception.
|
2012-09-19 12:32:39 +02:00
|
|
|
*
|
|
|
|
* @ingroup base
|
2012-05-15 10:58:14 +02:00
|
|
|
*/
|
2012-10-17 12:03:07 +02:00
|
|
|
class I2_BASE_API PosixException : public Exception
|
2012-04-22 16:45:31 +02:00
|
|
|
{
|
|
|
|
public:
|
2012-05-15 10:58:14 +02:00
|
|
|
/**
|
|
|
|
* Constructor for the PosixException class.
|
|
|
|
*
|
|
|
|
* @param message An error message.
|
|
|
|
* @param errorCode A Posix (errno) error code.
|
|
|
|
*/
|
2012-08-02 09:38:08 +02:00
|
|
|
inline PosixException(const String& message, int errorCode)
|
2012-05-26 21:30:04 +02:00
|
|
|
: Exception(message + ": " + FormatErrorCode(errorCode), errorCode)
|
|
|
|
{ }
|
2012-04-22 16:45:31 +02:00
|
|
|
|
2012-05-15 10:58:14 +02:00
|
|
|
/**
|
2012-08-02 09:38:08 +02:00
|
|
|
* Returns a String that describes the Posix error.
|
2012-05-15 10:58:14 +02:00
|
|
|
*
|
|
|
|
* @param code The Posix error code.
|
|
|
|
* @returns A description of the error.
|
|
|
|
*/
|
2012-08-02 09:38:08 +02:00
|
|
|
static String FormatErrorCode(int code);
|
2012-04-22 16:45:31 +02:00
|
|
|
};
|
|
|
|
|
2012-05-15 10:58:14 +02:00
|
|
|
/**
|
|
|
|
* An OpenSSL error encapsulated in an exception.
|
2012-09-19 12:32:39 +02:00
|
|
|
*
|
|
|
|
* @ingroup base
|
2012-05-15 10:58:14 +02:00
|
|
|
*/
|
2012-10-17 12:03:07 +02:00
|
|
|
class I2_BASE_API OpenSSLException : public Exception
|
2012-04-24 14:54:05 +02:00
|
|
|
{
|
|
|
|
public:
|
2012-05-15 10:58:14 +02:00
|
|
|
/**
|
|
|
|
* Constructor for the OpenSSLException class.
|
|
|
|
*
|
|
|
|
* @param message An error message.
|
|
|
|
* @param errorCode An OpenSSL error code.
|
|
|
|
*/
|
2012-08-02 09:38:08 +02:00
|
|
|
inline OpenSSLException(const String& message, int errorCode)
|
2012-05-26 21:30:04 +02:00
|
|
|
: Exception(message + ": " + FormatErrorCode(errorCode), errorCode)
|
|
|
|
{ }
|
2012-04-24 14:54:05 +02:00
|
|
|
|
2012-05-15 10:58:14 +02:00
|
|
|
/**
|
2012-08-02 09:38:08 +02:00
|
|
|
* Returns a String that describes the OpenSSL error.
|
2012-05-15 10:58:14 +02:00
|
|
|
*
|
|
|
|
* @param code The OpenSSL error code.
|
|
|
|
* @returns A description of the error.
|
|
|
|
*/
|
2012-08-02 09:38:08 +02:00
|
|
|
static String FormatErrorCode(int code);
|
2012-04-24 14:54:05 +02:00
|
|
|
};
|
|
|
|
|
2012-04-16 16:27:41 +02:00
|
|
|
}
|
|
|
|
|
2012-04-03 13:01:00 +02:00
|
|
|
#endif /* EXCEPTION_H */
|