2001-12-24 03:51:06 +01:00
|
|
|
/*
|
2004-12-12 02:55:57 +01:00
|
|
|
* PROGRAM: Firebird exceptions classes
|
|
|
|
* MODULE: fb_exception.h
|
2008-12-05 01:56:15 +01:00
|
|
|
* DESCRIPTION: Firebird's exception classes
|
2004-12-12 02:55:57 +01:00
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Initial
|
|
|
|
* Developer's Public License Version 1.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed AS IS,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing rights
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Mike Nordell
|
|
|
|
* for the Firebird Open Source RDBMS project.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2001 Mike Nordell <tamlin at algonet.se>
|
|
|
|
* and all contributors signed below.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
2001-12-24 03:51:06 +01:00
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2004-12-12 02:55:57 +01:00
|
|
|
|
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
#ifndef FB_EXCEPTION_H
|
|
|
|
#define FB_EXCEPTION_H
|
|
|
|
|
2004-03-01 04:35:23 +01:00
|
|
|
#include <stddef.h>
|
2004-05-03 06:25:06 +02:00
|
|
|
#include <string.h>
|
2009-06-13 18:36:10 +02:00
|
|
|
#include <new>
|
2001-12-24 03:51:06 +01:00
|
|
|
#include "fb_types.h"
|
2008-07-03 14:02:54 +02:00
|
|
|
#include "../common/StatusArg.h"
|
2001-12-24 03:51:06 +01:00
|
|
|
|
|
|
|
namespace Firebird {
|
|
|
|
|
2008-01-23 16:52:40 +01:00
|
|
|
class MemoryPool;
|
|
|
|
|
2006-05-19 17:17:02 +02:00
|
|
|
class Exception
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
Exception() throw() { }
|
|
|
|
public:
|
2009-07-21 15:59:45 +02:00
|
|
|
virtual ~Exception() throw();
|
2009-09-01 11:20:24 +02:00
|
|
|
virtual ISC_STATUS stuff_exception(ISC_STATUS* const status_vector) const throw() = 0;
|
2006-05-22 13:45:19 +02:00
|
|
|
virtual const char* what() const throw() = 0;
|
2006-05-19 17:17:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Used as jmpbuf to unwind when needed
|
|
|
|
class LongJump : public Exception
|
|
|
|
{
|
|
|
|
public:
|
2009-09-01 11:20:24 +02:00
|
|
|
virtual ISC_STATUS stuff_exception(ISC_STATUS* const status_vector) const throw();
|
2009-07-21 15:59:45 +02:00
|
|
|
virtual const char* what() const throw();
|
2006-05-19 17:17:02 +02:00
|
|
|
static void raise();
|
|
|
|
LongJump() throw() : Exception() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Used in MemoryPool
|
2009-06-13 18:36:10 +02:00
|
|
|
class BadAlloc : public std::bad_alloc, public Exception
|
2006-05-19 17:17:02 +02:00
|
|
|
{
|
|
|
|
public:
|
2009-09-01 11:20:24 +02:00
|
|
|
virtual ISC_STATUS stuff_exception(ISC_STATUS* const status_vector) const throw();
|
2009-07-21 15:59:45 +02:00
|
|
|
virtual const char* what() const throw();
|
2006-05-19 17:17:02 +02:00
|
|
|
static void raise();
|
2009-06-13 18:36:10 +02:00
|
|
|
BadAlloc() throw() : std::bad_alloc(), Exception() { }
|
2006-05-19 17:17:02 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Main exception class in firebird
|
|
|
|
class status_exception : public Exception
|
2001-12-24 03:51:06 +01:00
|
|
|
{
|
|
|
|
public:
|
2009-09-01 11:20:24 +02:00
|
|
|
status_exception(const ISC_STATUS *status_vector) throw();
|
2004-03-01 04:35:23 +01:00
|
|
|
virtual ~status_exception() throw();
|
2006-05-19 17:17:02 +02:00
|
|
|
|
2009-09-01 11:20:24 +02:00
|
|
|
virtual ISC_STATUS stuff_exception(ISC_STATUS* const status_vector) const throw();
|
2009-07-21 15:59:45 +02:00
|
|
|
virtual const char* what() const throw();
|
2006-05-19 17:17:02 +02:00
|
|
|
|
2006-01-07 17:50:13 +01:00
|
|
|
const ISC_STATUS* value() const throw() { return m_status_vector; }
|
2004-10-08 17:05:44 +02:00
|
|
|
|
2004-03-01 04:35:23 +01:00
|
|
|
static void raise(const ISC_STATUS *status_vector);
|
2008-07-03 14:02:54 +02:00
|
|
|
static void raise(const Arg::StatusVector& statusVector);
|
2008-12-05 01:56:15 +01:00
|
|
|
|
2006-01-07 17:50:13 +01:00
|
|
|
protected:
|
2008-12-05 01:56:15 +01:00
|
|
|
// Create exception with undefined status vector, this constructor allows
|
2006-01-07 17:50:13 +01:00
|
|
|
// derived classes create empty exception ...
|
|
|
|
status_exception() throw();
|
|
|
|
// .. and adjust it later using somehow created status vector.
|
2009-09-01 11:20:24 +02:00
|
|
|
void set_status(const ISC_STATUS *new_vector) throw();
|
2008-12-05 01:56:15 +01:00
|
|
|
|
2004-03-01 04:35:23 +01:00
|
|
|
private:
|
|
|
|
ISC_STATUS_ARRAY m_status_vector;
|
2002-11-11 19:06:01 +01:00
|
|
|
};
|
|
|
|
|
2009-08-26 15:08:54 +02:00
|
|
|
// Parameter syscall later in both system_error & system_call_failed
|
2009-08-27 04:19:36 +02:00
|
|
|
// must be literal string! This helps avoid need in StringsBuffer
|
2009-08-26 15:08:54 +02:00
|
|
|
// when processing this dangerous errors!
|
|
|
|
|
2008-12-01 02:26:27 +01:00
|
|
|
// use this class if exception can be handled
|
2008-11-27 21:16:46 +01:00
|
|
|
class system_error : public status_exception
|
2002-11-11 19:06:01 +01:00
|
|
|
{
|
2006-03-15 18:29:11 +01:00
|
|
|
private:
|
|
|
|
int errorCode;
|
2002-11-11 19:06:01 +01:00
|
|
|
public:
|
2008-11-27 21:16:46 +01:00
|
|
|
system_error(const char* syscall, int error_code);
|
2002-11-11 19:06:01 +01:00
|
|
|
|
2004-03-01 04:35:23 +01:00
|
|
|
static void raise(const char* syscall, int error_code);
|
|
|
|
static void raise(const char* syscall);
|
2008-12-05 01:56:15 +01:00
|
|
|
|
2006-03-15 18:29:11 +01:00
|
|
|
int getErrorCode() const
|
|
|
|
{
|
|
|
|
return errorCode;
|
|
|
|
}
|
2008-11-27 21:16:46 +01:00
|
|
|
|
|
|
|
static int getSystemError();
|
|
|
|
};
|
|
|
|
|
2008-12-05 01:56:15 +01:00
|
|
|
// use this class if exception can't be handled
|
2008-11-27 21:16:46 +01:00
|
|
|
// it will call abort() in DEV_BUILD to create core dump
|
|
|
|
class system_call_failed : public system_error
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
system_call_failed(const char* syscall, int error_code);
|
|
|
|
|
|
|
|
static void raise(const char* syscall, int error_code);
|
|
|
|
static void raise(const char* syscall);
|
2002-11-11 19:06:01 +01:00
|
|
|
};
|
|
|
|
|
2004-03-01 04:35:23 +01:00
|
|
|
class fatal_exception : public status_exception
|
2002-11-11 19:06:01 +01:00
|
|
|
{
|
|
|
|
public:
|
2003-12-31 06:36:12 +01:00
|
|
|
explicit fatal_exception(const char* message);
|
2004-11-11 22:46:25 +01:00
|
|
|
static void raiseFmt(const char* format, ...);
|
2009-07-21 15:59:45 +02:00
|
|
|
const char* what() const throw();
|
2003-12-31 06:36:12 +01:00
|
|
|
static void raise(const char* message);
|
2001-12-24 03:51:06 +01:00
|
|
|
};
|
|
|
|
|
2004-03-01 04:35:23 +01:00
|
|
|
|
2009-09-01 11:20:24 +02:00
|
|
|
// Serialize exception into status_vector
|
|
|
|
ISC_STATUS stuff_exception(ISC_STATUS *status_vector, const Firebird::Exception& ex) throw();
|
|
|
|
|
|
|
|
// Put status vector strings into strings buffer
|
|
|
|
void makePermanentVector(ISC_STATUS* perm, const ISC_STATUS* trans) throw();
|
|
|
|
void makePermanentVector(ISC_STATUS* v) throw();
|
2004-03-01 04:35:23 +01:00
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
} // namespace Firebird
|
|
|
|
|
2004-03-01 04:35:23 +01:00
|
|
|
|
2001-12-24 03:51:06 +01:00
|
|
|
#endif // FB_EXCEPTION_H
|