openPMD-api
Error.hpp
1 /* Copyright 2025 Axel Huebl, Franz Poeschel, Luca Fedeli
2  *
3  * This file is part of openPMD-api.
4  *
5  * openPMD-api is free software: you can redistribute it and/or modify
6  * it under the terms of of either the GNU General Public License or
7  * the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * openPMD-api is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License and the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * and the GNU Lesser General Public License along with openPMD-api.
19  * If not, see <http://www.gnu.org/licenses/>.
20  */
21 #pragma once
22 
23 #include "openPMD/ThrowError.hpp"
24 
25 #include <exception>
26 #include <optional>
27 #include <string>
28 #include <utility>
29 #include <vector>
30 
31 namespace openPMD
32 {
40 class Error : public std::exception
41 {
42 private:
43  std::string m_what;
44 
45 protected:
46  Error(std::string what) : m_what(what)
47  {}
48 
49 public:
50  virtual const char *what() const noexcept;
51 
52  Error(Error const &) = default;
53  Error(Error &&) = default;
54 
55  Error &operator=(Error const &) = default;
56  Error &operator=(Error &&) = default;
57 
58  virtual ~Error() noexcept = default;
59 };
60 
61 namespace error
62 {
70  {
71  public:
72  std::string backend;
74  std::string backend_in, std::string const &what);
75  };
76 
83  class WrongAPIUsage : public Error
84  {
85  public:
86  WrongAPIUsage(std::string const &what);
87  };
88 
89  class BackendConfigSchema : public Error
90  {
91  public:
92  std::vector<std::string> errorLocation;
93 
94  BackendConfigSchema(std::vector<std::string>, std::string what);
95  };
96 
102  class Internal : public Error
103  {
104  public:
105  Internal(std::string const &what);
106  };
107 
108  /*
109  * Read error concerning a specific object.
110  */
111  class ReadError : public Error
112  {
113  public:
114  AffectedObject affectedObject;
115  Reason reason;
116  // If empty, then the error is thrown by the frontend
117  std::optional<std::string> backend;
118  std::string description; // object path, further details, ...
119 
120  ReadError(
121  AffectedObject,
122  Reason,
123  std::optional<std::string> backend_in,
124  std::string description_in);
125  };
126 
127  class NoSuchAttribute : public Error
128  {
129  public:
130  NoSuchAttribute(std::string attributeName);
131  };
132 
134  {
135  public:
136  IllegalInOpenPMDStandard(std::string what);
137  };
138 } // namespace error
139 
145 
151 
157 } // namespace openPMD
Base class for all openPMD-specific error types.
Definition: Error.hpp:41
Definition: Error.hpp:90
Internal errors that should not happen.
Definition: Error.hpp:103
Definition: Error.hpp:128
An operation was requested that is not supported in a specific backend.
Definition: Error.hpp:70
Definition: Error.hpp:112
The API was used in an illegal way.
Definition: Error.hpp:84
Public definitions of openPMD-api.
Definition: Date.cpp:29