userver: /data/code/userver/odbc/include/userver/storages/odbc/exception.hpp Source File
Loading...
Searching...
No Matches
exception.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/storages/odbc/exception.hpp
4/// @brief ODBC storage exception hierarchy
5
6#include <cstddef>
7#include <stdexcept>
8#include <string>
9#include <string_view>
10#include <vector>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace storages::odbc {
15
16/// A single diagnostic record reported by the ODBC driver manager or driver.
17struct DiagnosticRecord final {
18 std::string sql_state;
19 int native_error{0};
20 std::string message;
21};
22
23class Error : public std::runtime_error {
24 using std::runtime_error::runtime_error;
25};
26
27class LogicError : public Error {
28 using Error::Error;
29};
30
31class RuntimeError : public Error {
32public:
33 using Error::Error;
34
35 RuntimeError(std::string message, std::vector<DiagnosticRecord> diagnostics, bool invalid_handle = false);
36
37 /// Structured driver diagnostics, in the order returned by ODBC.
38 const std::vector<DiagnosticRecord>& GetDiagnostics() const noexcept;
39
40 /// Whether any diagnostic has the specified two-character SQLSTATE class.
41 bool HasSqlStateClass(std::string_view sql_state_class) const noexcept;
42
43 /// Whether the failed ODBC call returned SQL_INVALID_HANDLE.
44 bool IsInvalidHandle() const noexcept;
45
46private:
47 std::vector<DiagnosticRecord> diagnostics_;
48 bool invalid_handle_{false};
49};
50
52 using RuntimeError::RuntimeError;
53};
54
56 using RuntimeError::RuntimeError;
57};
58
59/// Thrown when an ODBC pool cannot provide a connection for a non-timeout reason.
60class PoolError : public RuntimeError {
61 using RuntimeError::RuntimeError;
62};
63
64/// Thrown when the operation is aborted because an @ref engine::Deadline has expired
65/// (including task-inherited request deadlines).
67 using RuntimeError::RuntimeError;
68};
69
71 using LogicError::LogicError;
72};
73
75 using RuntimeError::RuntimeError;
76};
77
79public:
80 explicit RowIndexOutOfBounds(std::size_t index);
81};
82
84public:
85 explicit FieldIndexOutOfBounds(std::size_t index);
86};
87
88} // namespace storages::odbc
89
90USERVER_NAMESPACE_END