-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathError.hpp
More file actions
157 lines (137 loc) · 3.9 KB
/
Error.hpp
File metadata and controls
157 lines (137 loc) · 3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* Copyright 2025 Axel Huebl, Franz Poeschel, Luca Fedeli
*
* This file is part of openPMD-api.
*
* openPMD-api is free software: you can redistribute it and/or modify
* it under the terms of of either the GNU General Public License or
* the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* openPMD-api is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License and the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* and the GNU Lesser General Public License along with openPMD-api.
* If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "openPMD/ThrowError.hpp"
#include <exception>
#include <optional>
#include <string>
#include <utility>
#include <vector>
namespace openPMD
{
/**
* @brief Base class for all openPMD-specific error types.
*
* Should not be instantiated directly, but only by implementing child classes
* in the openPMD::error namespace.
*
*/
class Error : public std::exception
{
private:
std::string m_what;
protected:
Error(std::string what) : m_what(what)
{}
public:
virtual const char *what() const noexcept;
Error(Error const &) = default;
Error(Error &&) = default;
Error &operator=(Error const &) = default;
Error &operator=(Error &&) = default;
virtual ~Error() noexcept = default;
};
namespace error
{
/**
* @brief An operation was requested that is not supported in a specific
* backend.
*
* Example: Append mode is not available in JSON.
*/
class OperationUnsupportedInBackend : public Error
{
public:
std::string backend;
OperationUnsupportedInBackend(
std::string backend_in, std::string const &what);
};
/**
* @brief The API was used in an illegal way.
*
* Example: File-based iteration encoding is selected without specifying an
* expansion pattern.
*/
class WrongAPIUsage : public Error
{
public:
WrongAPIUsage(std::string const &what);
};
class BackendConfigSchema : public Error
{
public:
std::vector<std::string> errorLocation;
BackendConfigSchema(std::vector<std::string>, std::string what);
};
/**
* @brief Internal errors that should not happen. Please report.
*
* Example: A nullpointer is observed somewhere.
*/
class Internal : public Error
{
public:
Internal(std::string const &what);
};
/*
* Read error concerning a specific object.
*/
class ReadError : public Error
{
public:
AffectedObject affectedObject;
Reason reason;
// If empty, then the error is thrown by the frontend
std::optional<std::string> backend;
std::string description; // object path, further details, ...
ReadError(
AffectedObject,
Reason,
std::optional<std::string> backend_in,
std::string description_in);
};
class NoSuchAttribute : public Error
{
public:
NoSuchAttribute(std::string attributeName);
};
class IllegalInOpenPMDStandard : public Error
{
public:
IllegalInOpenPMDStandard(std::string what);
};
} // namespace error
/**
* @brief Backward-compatibility alias for no_such_file_error.
*
*/
using no_such_file_error = error::ReadError;
/**
* @brief Backward-compatibility alias for unsupported_data_error.
*
*/
using unsupported_data_error = error::OperationUnsupportedInBackend;
/**
* @brief Backward-compatibility alias for no_such_attribute_error.
*
*/
using no_such_attribute_error = error::NoSuchAttribute;
} // namespace openPMD