1 | //===----------------------------------------------------------------------===// |
2 | // DuckDB |
3 | // |
4 | // duckdb/common/exception.hpp |
5 | // |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #pragma once |
10 | |
11 | #include "duckdb/common/types.hpp" |
12 | |
13 | #include <stdarg.h> |
14 | #include <stdexcept> |
15 | |
16 | namespace duckdb { |
17 | |
18 | inline void assert_restrict_function(void *left_start, void *left_end, void *right_start, void *right_end, |
19 | const char *fname, int linenr) { |
20 | // assert that the two pointers do not overlap |
21 | #ifdef DEBUG |
22 | if (!(left_end <= right_start || right_end <= left_start)) { |
23 | printf("ASSERT RESTRICT FAILED: %s:%d\n" , fname, linenr); |
24 | assert(0); |
25 | } |
26 | #endif |
27 | } |
28 | |
29 | #define ASSERT_RESTRICT(left_start, left_end, right_start, right_end) \ |
30 | assert_restrict_function(left_start, left_end, right_start, right_end, __FILE__, __LINE__) |
31 | |
32 | //===--------------------------------------------------------------------===// |
33 | // Exception Types |
34 | //===--------------------------------------------------------------------===// |
35 | |
36 | enum class ExceptionType { |
37 | INVALID = 0, // invalid type |
38 | OUT_OF_RANGE = 1, // value out of range error |
39 | CONVERSION = 2, // conversion/casting error |
40 | UNKNOWN_TYPE = 3, // unknown type |
41 | DECIMAL = 4, // decimal related |
42 | MISMATCH_TYPE = 5, // type mismatch |
43 | DIVIDE_BY_ZERO = 6, // divide by 0 |
44 | OBJECT_SIZE = 7, // object size exceeded |
45 | INVALID_TYPE = 8, // incompatible for operation |
46 | SERIALIZATION = 9, // serialization |
47 | TRANSACTION = 10, // transaction management |
48 | NOT_IMPLEMENTED = 11, // method not implemented |
49 | EXPRESSION = 12, // expression parsing |
50 | CATALOG = 13, // catalog related |
51 | PARSER = 14, // parser related |
52 | PLANNER = 15, // planner related |
53 | SCHEDULER = 16, // scheduler related |
54 | EXECUTOR = 17, // executor related |
55 | CONSTRAINT = 18, // constraint related |
56 | INDEX = 19, // index related |
57 | STAT = 20, // stat related |
58 | CONNECTION = 21, // connection related |
59 | SYNTAX = 22, // syntax related |
60 | SETTINGS = 23, // settings related |
61 | BINDER = 24, // binder related |
62 | NETWORK = 25, // network related |
63 | OPTIMIZER = 26, // optimizer related |
64 | NULL_POINTER = 27, // nullptr exception |
65 | IO = 28, // IO exception |
66 | INTERRUPT = 29, // interrupt |
67 | FATAL = 30, // Fatal exception: fatal exceptions are non-recoverable, and render the entire DB in an unusable state |
68 | INTERNAL = |
69 | 31 // Internal exception: exception that indicates something went wrong internally (i.e. bug in the code base) |
70 | }; |
71 | |
72 | class Exception : public std::exception { |
73 | public: |
74 | Exception(string message); |
75 | Exception(ExceptionType exception_type, string message); |
76 | |
77 | ExceptionType type; |
78 | |
79 | public: |
80 | const char *what() const noexcept override; |
81 | |
82 | string ExceptionTypeToString(ExceptionType type); |
83 | |
84 | protected: |
85 | void Format(va_list ap); |
86 | |
87 | private: |
88 | string exception_message_; |
89 | }; |
90 | |
91 | //===--------------------------------------------------------------------===// |
92 | // Exception derived classes |
93 | //===--------------------------------------------------------------------===// |
94 | |
95 | //! Exceptions that are StandardExceptions do NOT invalidate the current transaction when thrown |
96 | class StandardException : public Exception { |
97 | public: |
98 | StandardException(ExceptionType exception_type, string message) : Exception(exception_type, message) { |
99 | } |
100 | }; |
101 | |
102 | class CatalogException : public StandardException { |
103 | public: |
104 | CatalogException(string msg, ...); |
105 | }; |
106 | |
107 | class ParserException : public StandardException { |
108 | public: |
109 | ParserException(string msg, ...); |
110 | }; |
111 | |
112 | class BinderException : public StandardException { |
113 | public: |
114 | BinderException(string msg, ...); |
115 | }; |
116 | |
117 | class CastException : public Exception { |
118 | public: |
119 | CastException(const TypeId origType, const TypeId newType); |
120 | }; |
121 | |
122 | class ValueOutOfRangeException : public Exception { |
123 | public: |
124 | ValueOutOfRangeException(const int64_t value, const TypeId origType, const TypeId newType); |
125 | ValueOutOfRangeException(const double value, const TypeId origType, const TypeId newType); |
126 | ValueOutOfRangeException(const TypeId varType, const idx_t length); |
127 | }; |
128 | |
129 | class ConversionException : public Exception { |
130 | public: |
131 | ConversionException(string msg, ...); |
132 | }; |
133 | |
134 | class InvalidTypeException : public Exception { |
135 | public: |
136 | InvalidTypeException(TypeId type, string msg); |
137 | }; |
138 | |
139 | class TypeMismatchException : public Exception { |
140 | public: |
141 | TypeMismatchException(const TypeId type_1, const TypeId type_2, string msg); |
142 | }; |
143 | |
144 | class TransactionException : public Exception { |
145 | public: |
146 | TransactionException(string msg, ...); |
147 | }; |
148 | |
149 | class NotImplementedException : public Exception { |
150 | public: |
151 | NotImplementedException(string msg, ...); |
152 | }; |
153 | |
154 | class OutOfRangeException : public Exception { |
155 | public: |
156 | OutOfRangeException(string msg, ...); |
157 | }; |
158 | |
159 | class SyntaxException : public Exception { |
160 | public: |
161 | SyntaxException(string msg, ...); |
162 | }; |
163 | |
164 | class ConstraintException : public Exception { |
165 | public: |
166 | ConstraintException(string msg, ...); |
167 | }; |
168 | |
169 | class IOException : public Exception { |
170 | public: |
171 | IOException(string msg, ...); |
172 | }; |
173 | |
174 | class SerializationException : public Exception { |
175 | public: |
176 | SerializationException(string msg, ...); |
177 | }; |
178 | |
179 | class SequenceException : public Exception { |
180 | public: |
181 | SequenceException(string msg, ...); |
182 | }; |
183 | |
184 | class InterruptException : public Exception { |
185 | public: |
186 | InterruptException(); |
187 | }; |
188 | |
189 | class FatalException : public Exception { |
190 | public: |
191 | FatalException(string msg, ...); |
192 | }; |
193 | |
194 | class InternalException : public Exception { |
195 | public: |
196 | InternalException(string msg, ...); |
197 | }; |
198 | |
199 | } // namespace duckdb |
200 | |