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
16namespace duckdb {
17
18inline 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
36enum 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
72class Exception : public std::exception {
73public:
74 Exception(string message);
75 Exception(ExceptionType exception_type, string message);
76
77 ExceptionType type;
78
79public:
80 const char *what() const noexcept override;
81
82 string ExceptionTypeToString(ExceptionType type);
83
84protected:
85 void Format(va_list ap);
86
87private:
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
96class StandardException : public Exception {
97public:
98 StandardException(ExceptionType exception_type, string message) : Exception(exception_type, message) {
99 }
100};
101
102class CatalogException : public StandardException {
103public:
104 CatalogException(string msg, ...);
105};
106
107class ParserException : public StandardException {
108public:
109 ParserException(string msg, ...);
110};
111
112class BinderException : public StandardException {
113public:
114 BinderException(string msg, ...);
115};
116
117class CastException : public Exception {
118public:
119 CastException(const TypeId origType, const TypeId newType);
120};
121
122class ValueOutOfRangeException : public Exception {
123public:
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
129class ConversionException : public Exception {
130public:
131 ConversionException(string msg, ...);
132};
133
134class InvalidTypeException : public Exception {
135public:
136 InvalidTypeException(TypeId type, string msg);
137};
138
139class TypeMismatchException : public Exception {
140public:
141 TypeMismatchException(const TypeId type_1, const TypeId type_2, string msg);
142};
143
144class TransactionException : public Exception {
145public:
146 TransactionException(string msg, ...);
147};
148
149class NotImplementedException : public Exception {
150public:
151 NotImplementedException(string msg, ...);
152};
153
154class OutOfRangeException : public Exception {
155public:
156 OutOfRangeException(string msg, ...);
157};
158
159class SyntaxException : public Exception {
160public:
161 SyntaxException(string msg, ...);
162};
163
164class ConstraintException : public Exception {
165public:
166 ConstraintException(string msg, ...);
167};
168
169class IOException : public Exception {
170public:
171 IOException(string msg, ...);
172};
173
174class SerializationException : public Exception {
175public:
176 SerializationException(string msg, ...);
177};
178
179class SequenceException : public Exception {
180public:
181 SequenceException(string msg, ...);
182};
183
184class InterruptException : public Exception {
185public:
186 InterruptException();
187};
188
189class FatalException : public Exception {
190public:
191 FatalException(string msg, ...);
192};
193
194class InternalException : public Exception {
195public:
196 InternalException(string msg, ...);
197};
198
199} // namespace duckdb
200