2003-02-17 14:28:17 +01:00
|
|
|
#include "firebird.h"
|
2014-09-29 13:03:47 +02:00
|
|
|
#include "firebird/Interface.h"
|
2002-11-11 19:06:01 +01:00
|
|
|
#include <string.h>
|
2004-03-01 04:35:23 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include "gen/iberror.h"
|
|
|
|
#include "../common/classes/alloc.h"
|
2008-01-23 16:52:40 +01:00
|
|
|
#include "../common/classes/init.h"
|
2009-09-01 11:20:24 +02:00
|
|
|
#include "../common/classes/array.h"
|
2014-08-15 16:19:02 +02:00
|
|
|
#include "../common/ThreadStart.h"
|
2010-10-12 10:02:57 +02:00
|
|
|
#include "../common/utils_proto.h"
|
2015-03-20 19:02:30 +01:00
|
|
|
#include "../common/SimpleStatusVector.h"
|
2011-01-14 18:31:40 +01:00
|
|
|
#include "../common/StatusHolder.h"
|
2009-09-01 11:20:24 +02:00
|
|
|
|
2006-01-07 17:55:40 +01:00
|
|
|
namespace Firebird {
|
|
|
|
|
2015-03-27 15:36:30 +01:00
|
|
|
// ********************************* Exception *******************************
|
|
|
|
|
|
|
|
Exception::~Exception() throw() { }
|
|
|
|
|
|
|
|
void Exception::stuffException(DynamicStatusVector& status_vector) const throw()
|
2007-09-26 19:50:31 +02:00
|
|
|
{
|
2015-03-27 18:51:19 +01:00
|
|
|
StaticStatusVector status;
|
2015-03-27 15:36:30 +01:00
|
|
|
stuffException(status);
|
2009-09-01 11:20:24 +02:00
|
|
|
try
|
2007-09-26 19:50:31 +02:00
|
|
|
{
|
2015-03-27 15:36:30 +01:00
|
|
|
status_vector.save(status.begin());
|
2009-09-01 11:20:24 +02:00
|
|
|
}
|
2015-03-28 01:36:04 +01:00
|
|
|
catch (const BadAlloc&)
|
2009-09-01 11:20:24 +02:00
|
|
|
{
|
2015-03-27 15:36:30 +01:00
|
|
|
ISC_STATUS tmp[3];
|
|
|
|
processUnexpectedException(tmp);
|
|
|
|
status_vector.save(tmp);
|
2009-09-01 11:20:24 +02:00
|
|
|
}
|
2007-09-26 19:50:31 +02:00
|
|
|
}
|
2008-08-27 14:20:47 +02:00
|
|
|
|
2015-03-27 18:51:19 +01:00
|
|
|
void Exception::stuffException(CheckStatusWrapper* status_vector) const throw()
|
2010-10-12 10:02:57 +02:00
|
|
|
{
|
2015-03-27 18:51:19 +01:00
|
|
|
StaticStatusVector status;
|
2015-03-27 15:36:30 +01:00
|
|
|
stuffException(status);
|
|
|
|
fb_utils::setIStatus(status_vector, status.begin());
|
2010-10-12 10:02:57 +02:00
|
|
|
}
|
|
|
|
|
2015-03-27 15:36:30 +01:00
|
|
|
void Exception::processUnexpectedException(ISC_STATUS* vector) throw()
|
2015-03-20 19:02:30 +01:00
|
|
|
{
|
2015-03-27 18:51:19 +01:00
|
|
|
// do not use stuffException() here to avoid endless loop
|
2015-03-20 19:02:30 +01:00
|
|
|
try
|
|
|
|
{
|
2015-03-27 15:36:30 +01:00
|
|
|
throw;
|
2015-03-20 19:02:30 +01:00
|
|
|
}
|
2015-03-28 01:36:04 +01:00
|
|
|
catch (const BadAlloc&)
|
2015-03-20 19:02:30 +01:00
|
|
|
{
|
2015-03-27 15:36:30 +01:00
|
|
|
fb_utils::statusBadAlloc(vector);
|
2015-03-20 19:02:30 +01:00
|
|
|
}
|
2015-03-28 01:36:04 +01:00
|
|
|
catch (const Exception&)
|
2015-03-20 19:02:30 +01:00
|
|
|
{
|
|
|
|
fb_assert(false);
|
|
|
|
|
2015-03-27 15:36:30 +01:00
|
|
|
fb_utils::statusUnknown(vector);
|
2015-03-20 19:02:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-17 16:10:11 +02:00
|
|
|
// ********************************* status_exception *******************************
|
2006-01-07 17:55:40 +01:00
|
|
|
|
2009-09-01 11:20:24 +02:00
|
|
|
status_exception::status_exception() throw()
|
2015-03-20 19:02:30 +01:00
|
|
|
: m_status_vector(m_buffer)
|
2004-03-07 08:58:55 +01:00
|
|
|
{
|
2015-03-20 19:02:30 +01:00
|
|
|
fb_utils::init_status(m_status_vector);
|
2004-03-01 04:35:23 +01:00
|
|
|
}
|
|
|
|
|
2009-09-01 11:20:24 +02:00
|
|
|
status_exception::status_exception(const ISC_STATUS *status_vector) throw()
|
2015-03-20 19:02:30 +01:00
|
|
|
: m_status_vector(m_buffer)
|
2004-03-07 08:58:55 +01:00
|
|
|
{
|
2015-03-20 19:02:30 +01:00
|
|
|
fb_utils::init_status(m_status_vector);
|
2006-07-27 16:17:02 +02:00
|
|
|
|
|
|
|
if (status_vector)
|
2006-05-23 15:03:34 +02:00
|
|
|
{
|
2009-09-01 11:20:24 +02:00
|
|
|
set_status(status_vector);
|
2006-01-07 17:55:40 +01:00
|
|
|
}
|
|
|
|
}
|
2008-12-05 02:20:14 +01:00
|
|
|
|
2015-04-14 19:00:45 +02:00
|
|
|
status_exception::status_exception(const status_exception& from) throw()
|
|
|
|
: m_status_vector(m_buffer)
|
|
|
|
{
|
|
|
|
fb_utils::init_status(m_status_vector);
|
|
|
|
|
|
|
|
set_status(from.m_status_vector);
|
|
|
|
}
|
|
|
|
|
2009-09-01 11:20:24 +02:00
|
|
|
void status_exception::set_status(const ISC_STATUS *new_vector) throw()
|
2005-12-25 05:01:49 +01:00
|
|
|
{
|
2009-09-01 11:20:24 +02:00
|
|
|
fb_assert(new_vector != 0);
|
2015-03-20 19:02:30 +01:00
|
|
|
unsigned len = fb_utils::statusLength(new_vector);
|
2004-03-07 08:58:55 +01:00
|
|
|
|
2015-03-20 19:02:30 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if (len >= FB_NELEM(m_buffer))
|
|
|
|
{
|
|
|
|
m_status_vector = FB_NEW(*getDefaultMemoryPool()) ISC_STATUS[len + 1];
|
|
|
|
}
|
|
|
|
len = makeDynamicStrings(len, m_status_vector, new_vector);
|
|
|
|
m_status_vector[len] = isc_arg_end;
|
|
|
|
}
|
2015-03-28 01:36:04 +01:00
|
|
|
catch (const Exception&)
|
2015-03-20 19:02:30 +01:00
|
|
|
{
|
|
|
|
if (m_status_vector != m_buffer)
|
|
|
|
{
|
|
|
|
delete[] m_status_vector;
|
|
|
|
m_status_vector = m_buffer;
|
|
|
|
}
|
2015-03-27 15:36:30 +01:00
|
|
|
processUnexpectedException(m_buffer);
|
2015-03-20 19:02:30 +01:00
|
|
|
}
|
2004-03-01 04:35:23 +01:00
|
|
|
}
|
|
|
|
|
2008-12-05 02:20:14 +01:00
|
|
|
status_exception::~status_exception() throw()
|
2006-01-07 17:55:40 +01:00
|
|
|
{
|
2015-03-23 10:06:10 +01:00
|
|
|
delete[] findDynamicStrings(fb_utils::statusLength(m_status_vector), m_status_vector);
|
2015-03-20 19:02:30 +01:00
|
|
|
if (m_status_vector != m_buffer)
|
|
|
|
{
|
|
|
|
delete[] m_status_vector;
|
|
|
|
}
|
2006-01-07 17:55:40 +01:00
|
|
|
}
|
|
|
|
|
2009-07-21 15:59:45 +02:00
|
|
|
const char* status_exception::what() const throw()
|
2005-12-25 05:01:49 +01:00
|
|
|
{
|
2009-07-21 15:59:45 +02:00
|
|
|
return "Firebird::status_exception";
|
2004-11-11 22:46:25 +01:00
|
|
|
}
|
|
|
|
|
2008-12-05 02:20:14 +01:00
|
|
|
void status_exception::raise(const ISC_STATUS *status_vector)
|
2004-03-07 08:58:55 +01:00
|
|
|
{
|
2009-09-01 11:20:24 +02:00
|
|
|
throw status_exception(status_vector);
|
|
|
|
}
|
|
|
|
|
2014-08-27 11:24:30 +02:00
|
|
|
void status_exception::raise(const IStatus* status)
|
|
|
|
{
|
2015-03-27 18:51:19 +01:00
|
|
|
StaticStatusVector status_vector;
|
2015-03-20 19:02:30 +01:00
|
|
|
status_vector.mergeStatus(status);
|
|
|
|
throw status_exception(status_vector.begin());
|
2014-08-27 11:24:30 +02:00
|
|
|
}
|
|
|
|
|
2008-07-03 14:02:54 +02:00
|
|
|
void status_exception::raise(const Arg::StatusVector& statusVector)
|
2004-03-07 08:58:55 +01:00
|
|
|
{
|
2009-09-01 11:20:24 +02:00
|
|
|
throw status_exception(statusVector.value());
|
2004-03-01 04:35:23 +01:00
|
|
|
}
|
|
|
|
|
2015-03-27 18:51:19 +01:00
|
|
|
void status_exception::stuffByException(StaticStatusVector& status) const throw()
|
2006-05-22 13:45:19 +02:00
|
|
|
{
|
2015-03-27 15:36:30 +01:00
|
|
|
try
|
2006-05-22 13:45:19 +02:00
|
|
|
{
|
2015-03-27 15:36:30 +01:00
|
|
|
status.assign(m_status_vector, fb_utils::statusLength(m_status_vector) + 1);
|
|
|
|
}
|
2015-03-28 01:36:04 +01:00
|
|
|
catch (const BadAlloc&)
|
2015-03-27 15:36:30 +01:00
|
|
|
{
|
|
|
|
processUnexpectedException(status.makeEmergencyStatus());
|
2006-05-22 13:45:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-17 16:10:11 +02:00
|
|
|
// ********************************* BadAlloc ****************************
|
2006-05-19 17:17:02 +02:00
|
|
|
|
|
|
|
void BadAlloc::raise()
|
|
|
|
{
|
|
|
|
throw BadAlloc();
|
|
|
|
}
|
|
|
|
|
2015-03-27 18:51:19 +01:00
|
|
|
void BadAlloc::stuffByException(StaticStatusVector& status) const throw()
|
2006-05-22 13:45:19 +02:00
|
|
|
{
|
2015-03-27 15:36:30 +01:00
|
|
|
fb_utils::statusBadAlloc(status.makeEmergencyStatus());
|
2006-05-22 13:45:19 +02:00
|
|
|
}
|
|
|
|
|
2009-07-21 15:59:45 +02:00
|
|
|
const char* BadAlloc::what() const throw()
|
|
|
|
{
|
|
|
|
return "Firebird::BadAlloc";
|
|
|
|
}
|
|
|
|
|
2009-04-17 16:10:11 +02:00
|
|
|
// ********************************* LongJump ***************************
|
2006-05-19 17:17:02 +02:00
|
|
|
|
|
|
|
void LongJump::raise()
|
|
|
|
{
|
|
|
|
throw LongJump();
|
|
|
|
}
|
|
|
|
|
2015-03-27 18:51:19 +01:00
|
|
|
void LongJump::stuffByException(StaticStatusVector& status) const throw()
|
2006-05-22 13:45:19 +02:00
|
|
|
{
|
2015-03-27 15:36:30 +01:00
|
|
|
ISC_STATUS sv[] = {isc_arg_gds, isc_random, isc_arg_string,
|
|
|
|
(ISC_STATUS)(IPTR) "Unexpected call to Firebird::LongJump::stuffException()", isc_arg_end};
|
2006-05-22 13:45:19 +02:00
|
|
|
|
2015-03-27 15:36:30 +01:00
|
|
|
try
|
2010-10-12 10:02:57 +02:00
|
|
|
{
|
2015-03-27 15:36:30 +01:00
|
|
|
status.assign(sv, FB_NELEM(sv));
|
|
|
|
}
|
2015-03-28 01:36:04 +01:00
|
|
|
catch (const BadAlloc&)
|
2015-03-27 15:36:30 +01:00
|
|
|
{
|
|
|
|
processUnexpectedException(status.makeEmergencyStatus());
|
2010-10-12 10:02:57 +02:00
|
|
|
}
|
2006-05-22 13:45:19 +02:00
|
|
|
}
|
|
|
|
|
2009-07-23 02:56:28 +02:00
|
|
|
const char* LongJump::what() const throw()
|
2009-07-21 15:59:45 +02:00
|
|
|
{
|
|
|
|
return "Firebird::LongJump";
|
|
|
|
}
|
|
|
|
|
2008-11-27 21:16:46 +01:00
|
|
|
|
2009-04-17 16:10:11 +02:00
|
|
|
// ********************************* system_error ***************************
|
2008-11-27 21:16:46 +01:00
|
|
|
|
2008-12-05 02:20:14 +01:00
|
|
|
system_error::system_error(const char* syscall, int error_code) :
|
2009-09-01 11:20:24 +02:00
|
|
|
status_exception(), errorCode(error_code)
|
2008-11-27 21:16:46 +01:00
|
|
|
{
|
|
|
|
Arg::Gds temp(isc_sys_request);
|
2009-08-26 15:08:54 +02:00
|
|
|
temp << Arg::Str(syscall);
|
2008-11-27 21:16:46 +01:00
|
|
|
temp << SYS_ERR(errorCode);
|
2009-09-01 11:20:24 +02:00
|
|
|
set_status(temp.value());
|
2008-11-27 21:16:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void system_error::raise(const char* syscall, int error_code)
|
|
|
|
{
|
|
|
|
throw system_error(syscall, error_code);
|
|
|
|
}
|
|
|
|
|
|
|
|
void system_error::raise(const char* syscall)
|
|
|
|
{
|
|
|
|
throw system_error(syscall, getSystemError());
|
|
|
|
}
|
|
|
|
|
|
|
|
int system_error::getSystemError()
|
|
|
|
{
|
|
|
|
#ifdef WIN_NT
|
|
|
|
return GetLastError();
|
|
|
|
#else
|
|
|
|
return errno;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-04-17 16:10:11 +02:00
|
|
|
// ********************************* system_call_failed ***************************
|
2004-03-01 04:35:23 +01:00
|
|
|
|
2008-12-05 02:20:14 +01:00
|
|
|
system_call_failed::system_call_failed(const char* syscall, int error_code) :
|
2008-11-27 21:16:46 +01:00
|
|
|
system_error(syscall, error_code)
|
2006-01-07 17:55:40 +01:00
|
|
|
{
|
2009-08-30 21:00:46 +02:00
|
|
|
// NS: something unexpected has happened. Log the error to log file
|
|
|
|
// In the future we may consider terminating the process even in PROD_BUILD
|
2009-11-15 19:38:34 +01:00
|
|
|
gds__log("Operating system call %s failed. Error code %d", syscall, error_code);
|
2008-12-01 08:28:13 +01:00
|
|
|
#ifdef DEV_BUILD
|
2008-12-05 02:20:14 +01:00
|
|
|
// raised failed system call exception in DEV_BUILD in 99.99% means
|
2008-09-04 12:00:35 +02:00
|
|
|
// problems with the code - let's create memory dump now
|
|
|
|
abort();
|
|
|
|
#endif
|
2004-03-01 04:35:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void system_call_failed::raise(const char* syscall, int error_code)
|
2002-11-11 19:06:01 +01:00
|
|
|
{
|
2004-03-01 04:35:23 +01:00
|
|
|
throw system_call_failed(syscall, error_code);
|
2002-11-11 19:06:01 +01:00
|
|
|
}
|
|
|
|
|
2004-03-01 04:35:23 +01:00
|
|
|
void system_call_failed::raise(const char* syscall)
|
2002-11-11 19:06:01 +01:00
|
|
|
{
|
2008-11-27 21:16:46 +01:00
|
|
|
throw system_call_failed(syscall, getSystemError());
|
2002-11-11 19:06:01 +01:00
|
|
|
}
|
|
|
|
|
2009-04-17 16:10:11 +02:00
|
|
|
// ********************************* fatal_exception *******************************
|
2004-03-01 04:35:23 +01:00
|
|
|
|
|
|
|
fatal_exception::fatal_exception(const char* message) :
|
2009-09-01 11:20:24 +02:00
|
|
|
status_exception()
|
2002-11-11 19:06:01 +01:00
|
|
|
{
|
2009-02-03 12:02:00 +01:00
|
|
|
const ISC_STATUS temp[] =
|
|
|
|
{
|
2009-01-03 20:02:04 +01:00
|
|
|
isc_arg_gds,
|
|
|
|
isc_random,
|
2009-09-03 03:28:54 +02:00
|
|
|
isc_arg_string,
|
2009-09-01 11:20:24 +02:00
|
|
|
(ISC_STATUS)(IPTR) message,
|
2009-01-03 20:02:04 +01:00
|
|
|
isc_arg_end
|
|
|
|
};
|
2009-09-01 11:20:24 +02:00
|
|
|
set_status(temp);
|
2002-11-11 19:06:01 +01:00
|
|
|
}
|
|
|
|
|
2004-10-07 11:27:34 +02:00
|
|
|
// Keep in sync with the constructor above, please; "message" becomes 4th element
|
2009-07-21 16:18:34 +02:00
|
|
|
// after initialization of status vector in constructor.
|
|
|
|
const char* fatal_exception::what() const throw()
|
|
|
|
{
|
|
|
|
return reinterpret_cast<const char*>(value()[3]);
|
|
|
|
}
|
2004-10-07 11:27:34 +02:00
|
|
|
|
2003-12-31 06:36:12 +01:00
|
|
|
void fatal_exception::raise(const char* message)
|
2002-11-11 19:06:01 +01:00
|
|
|
{
|
|
|
|
throw fatal_exception(message);
|
|
|
|
}
|
|
|
|
|
2009-07-21 15:59:45 +02:00
|
|
|
void fatal_exception::raiseFmt(const char* format, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
char buffer[1024];
|
|
|
|
VSNPRINTF(buffer, sizeof(buffer), format, args);
|
|
|
|
buffer[sizeof(buffer) - 1] = 0;
|
|
|
|
va_end(args);
|
|
|
|
throw fatal_exception(buffer);
|
|
|
|
}
|
|
|
|
|
2002-11-11 19:06:01 +01:00
|
|
|
} // namespace Firebird
|