2012-04-03 13:01:00 +02:00
|
|
|
#include "i2-base.h"
|
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2012-05-08 15:14:20 +02:00
|
|
|
/**
|
|
|
|
* Exception
|
|
|
|
*
|
|
|
|
* Default constructor for the Exception class.
|
|
|
|
*/
|
2012-04-03 13:01:00 +02:00
|
|
|
Exception::Exception(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-05-08 15:14:20 +02:00
|
|
|
/**
|
|
|
|
* Exception
|
|
|
|
*
|
|
|
|
* Constructor for the exception class.
|
|
|
|
*
|
|
|
|
* @param message A message describing the exception.
|
|
|
|
*/
|
2012-04-03 13:01:00 +02:00
|
|
|
Exception::Exception(const string& message)
|
|
|
|
{
|
2012-04-22 16:45:31 +02:00
|
|
|
SetMessage(message);
|
2012-04-03 13:01:00 +02:00
|
|
|
}
|
|
|
|
|
2012-05-08 15:14:20 +02:00
|
|
|
/**
|
|
|
|
* GetMessage
|
|
|
|
*
|
|
|
|
* Retrieves the description for the exception.
|
|
|
|
*
|
|
|
|
* @returns The description.
|
|
|
|
*/
|
2012-04-22 16:45:31 +02:00
|
|
|
string Exception::GetMessage(void) const
|
2012-04-03 13:01:00 +02:00
|
|
|
{
|
2012-04-22 16:45:31 +02:00
|
|
|
return m_Message;
|
2012-04-03 13:01:00 +02:00
|
|
|
}
|
|
|
|
|
2012-05-08 15:14:20 +02:00
|
|
|
/**
|
|
|
|
* SetMessage
|
|
|
|
*
|
|
|
|
* Sets the description for the exception.
|
|
|
|
*
|
|
|
|
* @param message The description.
|
|
|
|
*/
|
2012-04-22 16:45:31 +02:00
|
|
|
void Exception::SetMessage(string message)
|
2012-04-03 13:01:00 +02:00
|
|
|
{
|
2012-04-22 16:45:31 +02:00
|
|
|
m_Message = message;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2012-05-08 15:14:20 +02:00
|
|
|
/**
|
|
|
|
* FormatError
|
|
|
|
*
|
|
|
|
* Formats an Win32 error code.
|
|
|
|
*
|
|
|
|
* @param code The error code.
|
|
|
|
* @returns A string describing the error.
|
|
|
|
*/
|
2012-04-22 16:45:31 +02:00
|
|
|
string Win32Exception::FormatErrorCode(int code)
|
|
|
|
{
|
|
|
|
char *message;
|
|
|
|
string result = "Unknown error.";
|
|
|
|
|
|
|
|
DWORD rc = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
|
|
|
FORMAT_MESSAGE_FROM_SYSTEM, NULL, code, 0, (char *)&message,
|
|
|
|
0, NULL);
|
|
|
|
|
|
|
|
if (rc != 0) {
|
|
|
|
result = string(message);
|
|
|
|
LocalFree(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2012-04-03 13:01:00 +02:00
|
|
|
}
|
2012-04-22 16:45:31 +02:00
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
2012-05-08 15:14:20 +02:00
|
|
|
/**
|
|
|
|
* FormatError
|
|
|
|
*
|
|
|
|
* Formats a Posix error code.
|
|
|
|
*
|
|
|
|
* @param code The error code.
|
|
|
|
* @returns A string describing the error.
|
|
|
|
*/
|
2012-04-22 16:45:31 +02:00
|
|
|
string PosixException::FormatErrorCode(int code)
|
|
|
|
{
|
|
|
|
return strerror(code);
|
2012-04-23 09:48:20 +02:00
|
|
|
}
|
2012-04-24 14:54:05 +02:00
|
|
|
|
2012-05-08 15:14:20 +02:00
|
|
|
/**
|
|
|
|
* FormatError
|
|
|
|
*
|
|
|
|
* Formats an OpenSSL error code.
|
|
|
|
*
|
|
|
|
* @param code The error code.
|
|
|
|
* @returns A string describing the error.
|
|
|
|
*/
|
2012-04-24 14:54:05 +02:00
|
|
|
string OpenSSLException::FormatErrorCode(int code)
|
|
|
|
{
|
2012-04-26 12:55:48 +02:00
|
|
|
const char *message = ERR_error_string(code, NULL);
|
2012-04-24 14:54:05 +02:00
|
|
|
|
|
|
|
if (message == NULL)
|
|
|
|
message = "Unknown error.";
|
|
|
|
|
|
|
|
return message;
|
|
|
|
}
|