StormByte-Database 3.0.0
C++26 database module of the StormByte suite
Loading...
Searching...
No Matches
exception.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Database.
5 *
6 * StormByte-Database original source is dual-licensed:
7 *
8 * 1. GNU Lesser General Public License v3.0 (or later)
9 * You may redistribute and/or modify this file under the terms of the
10 * GNU Lesser General Public License as published by the Free Software
11 * Foundation, either version 3 of the License, or (at your option)
12 * any later version.
13 *
14 * 2. Commercial license
15 * Alternatively, this file may be used under the terms of a commercial
16 * license agreement with the copyright holder
17 * (David C. Manuelda <StormByte@gmail.com>).
18 *
19 * Both licenses apply only to original StormByte-Database source in this
20 * repository. They do not cover other StormByte modules or any third-party
21 * material shipped with this repository (including everything under
22 * thirdparty/, and in particular the bundled StormByte-Logger tree and
23 * the PostgreSQL, MariaDB and SQLite trees), which remain under their own
24 * licenses.
25 *
26 * Neither license grants any patent rights. Any patent licenses required
27 * to use this software or third-party components must be obtained separately
28 * from the patent holders.
29 *
30 * StormByte-Database is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
33 * GNU Lesser General Public License for more details.
34 *
35 * You should have received a copy of the GNU Lesser General Public License
36 * version 3 along with StormByte-Database. If not, see
37 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
38 *
39 * SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-StormByte-Commercial
40 */
41
42#pragma once
43
45#include <StormByte/exception.hxx>
46#include <StormByte/safe/string.hxx>
47#include <StormByte/size.hxx>
48
49#include <string_view>
50#include <utility>
51
56namespace StormByte {
61 namespace Database {
69 public:
74 struct Path {
75 std::string_view segments;
76
81 explicit constexpr Path(std::string_view segments) noexcept: segments(segments) {}
82 };
83
90 template <typename... Args>
91 requires (sizeof...(Args) >= 1)
92 Exception(std::string_view pattern, Args&&... args)
93 : StormByte::Exception(StormByte::Exception::Path{"Database"}, pattern, std::forward<Args>(args)...) {}
94
99 explicit Exception(std::string_view message);
100
106 Exception(Path path, std::string_view message);
107
115 template <typename... Args>
116 requires (sizeof...(Args) >= 1)
117 Exception(Path path, std::string_view pattern, Args&&... args)
118 : Exception(path, static_cast<std::string_view>(StormByte::Safe::String::ReplaceToken(pattern, std::forward<Args>(args)...))) {}
119
124 Exception(const Exception& other) = default;
125
130 Exception(Exception&& other) noexcept = default;
131
135 ~Exception() noexcept override;
136
142 Exception& operator=(const Exception& other) = default;
143
149 Exception& operator=(Exception&& other) noexcept = default;
150
151 protected:
158 static StormByte::Safe::String Segment(std::string_view prefix, std::string_view component) {
159 StormByte::Safe::String path{prefix};
160 path.append(component);
161 return path;
162 }
163 };
164
170 public:
175 explicit ConnectionError(std::string_view error);
176
181 ConnectionError(const ConnectionError& other) = default;
182
187 ConnectionError(ConnectionError&& other) noexcept = default;
188
192 ~ConnectionError() noexcept override;
193
199 ConnectionError& operator=(const ConnectionError& other) = default;
200
206 ConnectionError& operator=(ConnectionError&& other) noexcept = default;
207 };
208
214 public:
219 explicit WrongValueType(std::string_view error);
220
228 template <typename... Args>
229 requires (sizeof...(Args) >= 1)
230 WrongValueType(std::string_view component, std::string_view pattern, Args&&... args)
231 : Exception(Path{Segment("WrongValueType.", component)}, pattern, std::forward<Args>(args)...) {}
232
237 WrongValueType(const WrongValueType& other) = default;
238
243 WrongValueType(WrongValueType&& other) noexcept = default;
244
248 ~WrongValueType() noexcept override;
249
255 WrongValueType& operator=(const WrongValueType& other) = default;
256
262 WrongValueType& operator=(WrongValueType&& other) noexcept = default;
263 };
264
270 public:
275 explicit ColumnNotFound(std::string_view column);
276
281 ColumnNotFound(const ColumnNotFound& other) = default;
282
287 ColumnNotFound(ColumnNotFound&& other) noexcept = default;
288
292 ~ColumnNotFound() noexcept override;
293
299 ColumnNotFound& operator=(const ColumnNotFound& other) = default;
300
306 ColumnNotFound& operator=(ColumnNotFound&& other) noexcept = default;
307 };
308
314 public:
321
326 OutOfBounds(const OutOfBounds& other) = default;
327
332 OutOfBounds(OutOfBounds&& other) noexcept = default;
333
337 ~OutOfBounds() noexcept override;
338
344 OutOfBounds& operator=(const OutOfBounds& other) = default;
345
351 OutOfBounds& operator=(OutOfBounds&& other) noexcept = default;
352 };
353
359 public:
364 explicit QueryException(std::string_view error);
365
373 template <typename... Args>
374 requires (sizeof...(Args) >= 1)
375 QueryException(std::string_view component, std::string_view pattern, Args&&... args)
376 : Exception(Path{Segment("Query.", component)}, pattern, std::forward<Args>(args)...) {}
377
382 QueryException(const QueryException& other) = default;
383
388 QueryException(QueryException&& other) noexcept = default;
389
393 ~QueryException() noexcept override;
394
400 QueryException& operator=(const QueryException& other) = default;
401
407 QueryException& operator=(QueryException&& other) noexcept = default;
408 };
409
415 public:
420 explicit UnknownSTMT(std::string_view name);
421
426 UnknownSTMT(const UnknownSTMT& other) = default;
427
432 UnknownSTMT(UnknownSTMT&& other) noexcept = default;
433
437 ~UnknownSTMT() noexcept override;
438
444 UnknownSTMT& operator=(const UnknownSTMT& other) = default;
445
451 UnknownSTMT& operator=(UnknownSTMT&& other) noexcept = default;
452 };
453
459 public:
464 explicit ExecuteError(std::string_view error);
465
470 ExecuteError(const ExecuteError& other) = default;
471
476 ExecuteError(ExecuteError&& other) noexcept = default;
477
481 ~ExecuteError() noexcept override;
482
488 ExecuteError& operator=(const ExecuteError& other) = default;
489
495 ExecuteError& operator=(ExecuteError&& other) noexcept = default;
496 };
497
503 public:
508 explicit TransactionError(std::string_view error);
509
514 TransactionError(const TransactionError& other) = default;
515
520 TransactionError(TransactionError&& other) noexcept = default;
521
525 ~TransactionError() noexcept override;
526
532 TransactionError& operator=(const TransactionError& other) = default;
533
539 TransactionError& operator=(TransactionError&& other) noexcept = default;
540 };
541 }
542}
543
546
549
552
555
558
561
564
567
Column name missing from a Row.
Definition exception.hxx:269
ColumnNotFound(const ColumnNotFound &other)=default
Copy constructor.
~ColumnNotFound() noexcept override
Destructor.
ColumnNotFound(ColumnNotFound &&other) noexcept=default
Move constructor.
ColumnNotFound(std::string_view column)
Construct from the missing name.
Connection failed.
Definition exception.hxx:169
ConnectionError(ConnectionError &&other) noexcept=default
Move constructor.
ConnectionError(std::string_view error)
Construct from a backend message.
~ConnectionError() noexcept override
Destructor.
ConnectionError(const ConnectionError &other)=default
Copy constructor.
Abstract backend.
Definition database.hxx:73
Exception(Path path, std::string_view message)
Plain message under an additional Database path.
~Exception() noexcept override
Destructor.
Exception(Path path, std::string_view pattern, Args &&... args)
Replace literal {} under an additional Database path.
Definition exception.hxx:117
Exception(std::string_view pattern, Args &&... args)
Replace literal {} under StormByte.Database.
Definition exception.hxx:92
Exception(Exception &&other) noexcept=default
Move constructor.
Exception(std::string_view message)
Copy a plain message under StormByte.Database.
static StormByte::Safe::String Segment(std::string_view prefix, std::string_view component)
Join a fixed prefix and a dynamic segment.
Definition exception.hxx:158
Exception(const Exception &other)=default
Copy constructor.
Query or statement execution failed.
Definition exception.hxx:458
ExecuteError(ExecuteError &&other) noexcept=default
Move constructor.
ExecuteError(std::string_view error)
Construct from a backend message.
ExecuteError(const ExecuteError &other)=default
Copy constructor.
~ExecuteError() noexcept override
Destructor.
Column index out of range.
Definition exception.hxx:313
~OutOfBounds() noexcept override
Destructor.
OutOfBounds(OutOfBounds &&other) noexcept=default
Move constructor.
OutOfBounds(StormByte::Size pos, StormByte::Size size)
Construct from index and size.
OutOfBounds(const OutOfBounds &other)=default
Copy constructor.
Base for query errors.
Definition exception.hxx:358
QueryException(const QueryException &other)=default
Copy constructor.
QueryException(std::string_view error)
Construct from an error message.
QueryException(QueryException &&other) noexcept=default
Move constructor.
QueryException(std::string_view component, std::string_view pattern, Args &&... args)
Replace literal {} under StormByte.Database.Query.
Definition exception.hxx:375
~QueryException() noexcept override
Destructor.
TransactionError(TransactionError &&other) noexcept=default
Move constructor.
TransactionError(std::string_view error)
Construct from the failure reason.
TransactionError(const TransactionError &other)=default
Copy constructor.
~TransactionError() noexcept override
Destructor.
Prepared statement name is not registered.
Definition exception.hxx:414
UnknownSTMT(const UnknownSTMT &other)=default
Copy constructor.
UnknownSTMT(std::string_view name)
Construct from the statement name.
~UnknownSTMT() noexcept override
Destructor.
UnknownSTMT(UnknownSTMT &&other) noexcept=default
Move constructor.
Value accessed as the wrong type.
Definition exception.hxx:213
WrongValueType(WrongValueType &&other) noexcept=default
Move constructor.
WrongValueType(std::string_view component, std::string_view pattern, Args &&... args)
Replace literal {} under StormByte.Database.WrongValueType.
Definition exception.hxx:230
~WrongValueType() noexcept override
Destructor.
WrongValueType(const WrongValueType &other)=default
Copy constructor.
WrongValueType(std::string_view error)
Construct from an error message.
String & append(std::string_view text)
static String ReplaceToken(std::string_view text, Args &&... args)
STORMBYTE_DECLARE_MAYBE_SAFE(StormByte::Logger::Exception)
Database module of the StormByte suite.
Root namespace of the StormByte C++ suite.
STL namespace.
Additional path segments nested below StormByte.Database.
Definition exception.hxx:74
constexpr Path(std::string_view segments) noexcept
Wraps additional path segments.
Definition exception.hxx:81
std::string_view segments
Additional dotted path segments.
Definition exception.hxx:75
#define STORMBYTE_DATABASE_PUBLIC
Definition visibility.h:54