1 | /* |
2 | * PROGRAM: Firebird exceptions classes |
3 | * MODULE: fb_exception.h |
4 | * DESCRIPTION: Firebird's exception classes |
5 | * |
6 | * The contents of this file are subject to the Initial |
7 | * Developer's Public License Version 1.0 (the "License"); |
8 | * you may not use this file except in compliance with the |
9 | * License. You may obtain a copy of the License at |
10 | * http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl. |
11 | * |
12 | * Software distributed under the License is distributed AS IS, |
13 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. |
14 | * See the License for the specific language governing rights |
15 | * and limitations under the License. |
16 | * |
17 | * The Original Code was created by Mike Nordell |
18 | * for the Firebird Open Source RDBMS project. |
19 | * |
20 | * Copyright (c) 2001 Mike Nordell <tamlin at algonet.se> |
21 | * and all contributors signed below. |
22 | * |
23 | * All Rights Reserved. |
24 | * Contributor(s): ______________________________________. |
25 | * |
26 | * |
27 | */ |
28 | |
29 | |
30 | #ifndef FB_EXCEPTION_H |
31 | #define FB_EXCEPTION_H |
32 | |
33 | #include <stddef.h> |
34 | #include <string.h> |
35 | |
36 | #ifndef ANDROID |
37 | #define USE_SYSTEM_NEW |
38 | #endif |
39 | |
40 | #ifdef USE_SYSTEM_NEW |
41 | #include <new> |
42 | #endif |
43 | |
44 | #include "fb_types.h" |
45 | #include "../common/StatusArg.h" |
46 | #include "../common/thd.h" |
47 | |
48 | namespace Firebird |
49 | { |
50 | class IStatus; |
51 | class MemoryPool; |
52 | |
53 | class Exception |
54 | { |
55 | protected: |
56 | Exception() throw() { } |
57 | public: |
58 | ISC_STATUS stuff_exception(ISC_STATUS* const status_vector) const throw(); |
59 | virtual ~Exception() throw(); |
60 | virtual ISC_STATUS stuffException(IStatus* status_vector) const throw() = 0; |
61 | virtual const char* what() const throw() = 0; |
62 | }; |
63 | |
64 | // Used as jmpbuf to unwind when needed |
65 | class LongJump : public Exception |
66 | { |
67 | public: |
68 | virtual ISC_STATUS stuffException(IStatus* status_vector) const throw(); |
69 | virtual const char* what() const throw(); |
70 | static void raise(); |
71 | LongJump() throw() : Exception() { } |
72 | }; |
73 | |
74 | // Used in MemoryPool |
75 | #ifdef USE_SYSTEM_NEW |
76 | |
77 | class BadAlloc : public std::bad_alloc, public Exception |
78 | { |
79 | public: |
80 | BadAlloc() throw() : std::bad_alloc(), Exception() { } |
81 | #else // USE_SYSTEM_NEW |
82 | |
83 | class BadAlloc : public Exception |
84 | { |
85 | public: |
86 | BadAlloc() throw() : Exception() { } |
87 | #endif // USE_SYSTEM_NEW |
88 | |
89 | public: |
90 | virtual ISC_STATUS stuffException(IStatus* status_vector) const throw(); |
91 | virtual const char* what() const throw(); |
92 | static void raise(); |
93 | }; |
94 | |
95 | // Main exception class in firebird |
96 | class status_exception : public Exception |
97 | { |
98 | public: |
99 | status_exception(const ISC_STATUS *status_vector) throw(); |
100 | virtual ~status_exception() throw(); |
101 | |
102 | virtual ISC_STATUS stuffException(IStatus* status_vector) const throw(); |
103 | virtual const char* what() const throw(); |
104 | |
105 | const ISC_STATUS* value() const throw() { return m_status_vector; } |
106 | |
107 | static void raise(const ISC_STATUS *status_vector); |
108 | static void raise(const Arg::StatusVector& statusVector); |
109 | |
110 | protected: |
111 | // Create exception with undefined status vector, this constructor allows |
112 | // derived classes create empty exception ... |
113 | status_exception() throw(); |
114 | // .. and adjust it later using somehow created status vector. |
115 | void set_status(const ISC_STATUS *new_vector) throw(); |
116 | |
117 | private: |
118 | ISC_STATUS_ARRAY m_status_vector; |
119 | }; |
120 | |
121 | // Parameter syscall later in both system_error & system_call_failed |
122 | // must be literal string! This helps avoid need in StringsBuffer |
123 | // when processing this dangerous errors! |
124 | |
125 | // use this class if exception can be handled |
126 | class system_error : public status_exception |
127 | { |
128 | private: |
129 | int errorCode; |
130 | public: |
131 | system_error(const char* syscall, int error_code); |
132 | |
133 | static void raise(const char* syscall, int error_code); |
134 | static void raise(const char* syscall); |
135 | |
136 | int getErrorCode() const |
137 | { |
138 | return errorCode; |
139 | } |
140 | |
141 | static int getSystemError(); |
142 | }; |
143 | |
144 | // use this class if exception can't be handled |
145 | // it will call abort() in DEV_BUILD to create core dump |
146 | class system_call_failed : public system_error |
147 | { |
148 | public: |
149 | system_call_failed(const char* syscall, int error_code); |
150 | |
151 | static void raise(const char* syscall, int error_code); |
152 | static void raise(const char* syscall); |
153 | }; |
154 | |
155 | class fatal_exception : public status_exception |
156 | { |
157 | public: |
158 | explicit fatal_exception(const char* message); |
159 | static void raiseFmt(const char* format, ...); |
160 | const char* what() const throw(); |
161 | static void raise(const char* message); |
162 | }; |
163 | |
164 | |
165 | // Put status vector strings into strings buffer |
166 | void makePermanentVector(ISC_STATUS* perm, const ISC_STATUS* trans, ThreadId thr = getThreadId()) throw(); |
167 | void makePermanentVector(ISC_STATUS* v, ThreadId thr = getThreadId()) throw(); |
168 | |
169 | } // namespace Firebird |
170 | |
171 | |
172 | #endif // FB_EXCEPTION_H |
173 | |