OpenVDB: Exceptions.h Source File

OpenVDB 5.2.0

Exceptions.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2018 DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
30
31 #ifndef OPENVDB_EXCEPTIONS_HAS_BEEN_INCLUDED
32 #define OPENVDB_EXCEPTIONS_HAS_BEEN_INCLUDED
33
34 #include <openvdb/version.h>
35 #include <exception>
36 #include <sstream>
37 #include <string>
38
39
40 namespace openvdb {
41 OPENVDB_USE_VERSION_NAMESPACE
42 namespace OPENVDB_VERSION_NAME {
43
44 class OPENVDB_API Exception: public std::exception
45 {
46 public:
47 Exception(const Exception&) = default;
48 Exception(Exception&&) = default;
49 Exception& operator=(const Exception&) = default;
50 Exception& operator=(Exception&&) = default;
51 ~Exception() override = default;
52
53 const char* what() const noexcept override
54 {
55 try { return mMessage.c_str(); } catch (...) {}
56 return nullptr;
57 }
58
59 protected:
60 Exception() noexcept {}
61 explicit Exception(const char* eType, const std::string* const msg = nullptr) noexcept
62 {
63 try {
64 if (eType) mMessage = eType;
65 if (msg) mMessage += ": " + (*msg);
66 } catch (...) {}
67 }
68
69 private:
70 std::string mMessage;
71 };
72
73
74 #define OPENVDB_EXCEPTION(_classname) \
75 class OPENVDB_API _classname: public Exception \
76 { \
77 public: \
78 _classname() noexcept: Exception( #_classname ) {} \
79 explicit _classname(const std::string& msg) noexcept: Exception( #_classname , &msg) {} \
80 }
81
82
83 OPENVDB_EXCEPTION(ArithmeticError);
84 OPENVDB_EXCEPTION(IndexError);
85 OPENVDB_EXCEPTION(IoError);
86 OPENVDB_EXCEPTION(KeyError);
87 OPENVDB_EXCEPTION(LookupError);
88 OPENVDB_EXCEPTION(NotImplementedError);
89 OPENVDB_EXCEPTION(ReferenceError);
90 OPENVDB_EXCEPTION(RuntimeError);
91 OPENVDB_EXCEPTION(TypeError);
92 OPENVDB_EXCEPTION(ValueError);
93
94 #undef OPENVDB_EXCEPTION
95
96
98 class OPENVDB_API IllegalValueException: public Exception {
99 public:
100 OPENVDB_DEPRECATED IllegalValueException() noexcept: Exception("IllegalValueException") {}
101 OPENVDB_DEPRECATED explicit IllegalValueException(const std::string& msg) noexcept:
102 Exception("IllegalValueException", &msg) {}
103 };
104
105 } // namespace OPENVDB_VERSION_NAME
106 } // namespace openvdb
107
108
109 #define OPENVDB_THROW(exception, message) \
110 { \
111 std::string _openvdb_throw_msg; \
112 try { \
113 std::ostringstream _openvdb_throw_os; \
114 _openvdb_throw_os << message; \
115 _openvdb_throw_msg = _openvdb_throw_os.str(); \
116 } catch (...) {} \
117 throw exception(_openvdb_throw_msg); \
118 } // OPENVDB_THROW
119
120 #endif // OPENVDB_EXCEPTIONS_HAS_BEEN_INCLUDED
121
122 // Copyright (c) 2012-2018 DreamWorks Animation LLC
123 // All rights reserved. This software is distributed under the
124 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
OPENVDB_API
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:194
OPENVDB_DEPRECATED
#define OPENVDB_DEPRECATED
Definition: Platform.h:49
openvdb::v5_2::LookupError
Definition: Exceptions.h:87
openvdb::v5_2::TypeError
Definition: Exceptions.h:91
openvdb::v5_2::Exception::Exception
Exception(const char *eType, const std::string *const msg=nullptr) noexcept
Definition: Exceptions.h:61
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
openvdb::v5_2::IllegalValueException::IllegalValueException
OPENVDB_DEPRECATED IllegalValueException() noexcept
Definition: Exceptions.h:100
openvdb::v5_2::ValueError
Definition: Exceptions.h:92
openvdb::v5_2::IllegalValueException
Definition: Exceptions.h:98
openvdb::v5_2::ReferenceError
Definition: Exceptions.h:89
openvdb::v5_2::Exception::Exception
Exception() noexcept
Definition: Exceptions.h:60
openvdb
Definition: Exceptions.h:40
openvdb::v5_2::RuntimeError
Definition: Exceptions.h:90
openvdb::v5_2::IllegalValueException::IllegalValueException
OPENVDB_DEPRECATED IllegalValueException(const std::string &msg) noexcept
Definition: Exceptions.h:101
version.h
Library and file format version numbers.
openvdb::v5_2::Exception::what
const char * what() const noexcept override
Definition: Exceptions.h:53
openvdb::v5_2::IndexError
Definition: Exceptions.h:84
openvdb::v5_2::KeyError
Definition: Exceptions.h:86
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
OPENVDB_EXCEPTION
#define OPENVDB_EXCEPTION(_classname)
Definition: Exceptions.h:74
openvdb::v5_2::NotImplementedError
Definition: Exceptions.h:88
openvdb::v5_2::ArithmeticError
Definition: Exceptions.h:83
openvdb::v5_2::Exception
Definition: Exceptions.h:44
openvdb::v5_2::IoError
Definition: Exceptions.h:85