OpenVDB  7.0.0
Exceptions.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 
4 #ifndef OPENVDB_EXCEPTIONS_HAS_BEEN_INCLUDED
5 #define OPENVDB_EXCEPTIONS_HAS_BEEN_INCLUDED
6 
7 #include <openvdb/version.h>
8 #include <exception>
9 #include <sstream>
10 #include <string>
11 
12 
13 namespace openvdb {
15 namespace OPENVDB_VERSION_NAME {
16 
17 class OPENVDB_API Exception: public std::exception
18 {
19 public:
20  Exception(const Exception&) = default;
21  Exception(Exception&&) = default;
22  Exception& operator=(const Exception&) = default;
23  Exception& operator=(Exception&&) = default;
24  ~Exception() override = default;
25 
26  const char* what() const noexcept override
27  {
28  try { return mMessage.c_str(); } catch (...) {}
29  return nullptr;
30  }
31 
32 protected:
33  Exception() noexcept {}
34  explicit Exception(const char* eType, const std::string* const msg = nullptr) noexcept
35  {
36  try {
37  if (eType) mMessage = eType;
38  if (msg) mMessage += ": " + (*msg);
39  } catch (...) {}
40  }
41 
42 private:
43  std::string mMessage;
44 };
45 
46 
47 #define OPENVDB_EXCEPTION(_classname) \
48 class OPENVDB_API _classname: public Exception \
49 { \
50 public: \
51  _classname() noexcept: Exception( #_classname ) {} \
52  explicit _classname(const std::string& msg) noexcept: Exception( #_classname , &msg) {} \
53 }
54 
55 
66 
67 #undef OPENVDB_EXCEPTION
68 
69 
72 public:
74  OPENVDB_DEPRECATED explicit IllegalValueException(const std::string& msg) noexcept:
75  Exception("IllegalValueException", &msg) {}
76 };
77 
78 } // namespace OPENVDB_VERSION_NAME
79 } // namespace openvdb
80 
81 
82 #define OPENVDB_THROW(exception, message) \
83 { \
84  std::string _openvdb_throw_msg; \
85  try { \
86  std::ostringstream _openvdb_throw_os; \
87  _openvdb_throw_os << message; \
88  _openvdb_throw_msg = _openvdb_throw_os.str(); \
89  } catch (...) {} \
90  throw exception(_openvdb_throw_msg); \
91 } // OPENVDB_THROW
92 
93 #endif // OPENVDB_EXCEPTIONS_HAS_BEEN_INCLUDED
OPENVDB_EXCEPTION
#define OPENVDB_EXCEPTION(_classname)
Definition: Exceptions.h:47
openvdb::v7_0::LookupError
Definition: Exceptions.h:60
openvdb::v7_0::IllegalValueException::IllegalValueException
IllegalValueException() noexcept
Definition: Exceptions.h:73
openvdb::v7_0::ReferenceError
Definition: Exceptions.h:62
openvdb::v7_0::NotImplementedError
Definition: Exceptions.h:61
openvdb::v7_0::Exception::Exception
Exception(const char *eType, const std::string *const msg=nullptr) noexcept
Definition: Exceptions.h:34
version.h
Library and file format version numbers.
openvdb::v7_0::KeyError
Definition: Exceptions.h:59
OPENVDB_API
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:230
OPENVDB_DEPRECATED
#define OPENVDB_DEPRECATED
Definition: Platform.h:42
openvdb::v7_0::TypeError
Definition: Exceptions.h:64
openvdb::v7_0::Exception::Exception
Exception() noexcept
Definition: Exceptions.h:33
openvdb::v7_0::RuntimeError
Definition: Exceptions.h:63
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
openvdb::v7_0::Exception::what
const char * what() const noexcept override
Definition: Exceptions.h:26
openvdb::v7_0::IllegalValueException
Definition: Exceptions.h:71
openvdb::v7_0::IndexError
Definition: Exceptions.h:57
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
openvdb::v7_0::ValueError
Definition: Exceptions.h:65
openvdb
Definition: Exceptions.h:13
openvdb::v7_0::IoError
Definition: Exceptions.h:58
openvdb::v7_0::Exception
Definition: Exceptions.h:17
openvdb::v7_0::ArithmeticError
Definition: Exceptions.h:56
openvdb::v7_0::IllegalValueException::IllegalValueException
IllegalValueException(const std::string &msg) noexcept
Definition: Exceptions.h:74