OpenVDB  5.0.0
Exceptions.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2017 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 <exception>
35 #include <string>
36 #include <iostream>
37 #include <openvdb/version.h>
38 
39 namespace openvdb {
41 namespace OPENVDB_VERSION_NAME {
42 
43 class OPENVDB_API Exception: public std::exception
44 {
45 public:
46  Exception(const Exception&) = default;
47  Exception(Exception&&) = default;
48  Exception& operator=(const Exception&) = default;
49  Exception& operator=(Exception&&) = default;
50  ~Exception() override = default;
51 
52  const char* what() const noexcept override
53  {
54  try { return mMessage.c_str(); } catch (...) {}
55  return nullptr;
56  }
57 
58 protected:
59  Exception() noexcept {}
60  explicit Exception(const char* eType, const std::string* const msg = nullptr) noexcept
61  {
62  try {
63  if (eType) mMessage = eType;
64  if (msg) mMessage += ": " + (*msg);
65  } catch (...) {}
66  }
67 
68 private:
69  std::string mMessage;
70 };
71 
72 
73 #define OPENVDB_EXCEPTION(_classname) \
74 class OPENVDB_API _classname: public Exception \
75 { \
76 public: \
77  _classname() noexcept: Exception( #_classname ) {} \
78  explicit _classname(const std::string& msg) noexcept: Exception( #_classname , &msg) {} \
79 }
80 
81 
92 
93 #undef OPENVDB_EXCEPTION
94 
95 
98 public:
100  OPENVDB_DEPRECATED explicit IllegalValueException(const std::string& msg) noexcept:
101  Exception("IllegalValueException", &msg) {}
102 };
103 
104 } // namespace OPENVDB_VERSION_NAME
105 } // namespace openvdb
106 
107 
108 #define OPENVDB_THROW(exception, message) \
109 { \
110  std::string _openvdb_throw_msg; \
111  try { \
112  std::ostringstream _openvdb_throw_os; \
113  _openvdb_throw_os << message; \
114  _openvdb_throw_msg = _openvdb_throw_os.str(); \
115  } catch (...) {} \
116  throw exception(_openvdb_throw_msg); \
117 } // OPENVDB_THROW
118 
119 #endif // OPENVDB_EXCEPTIONS_HAS_BEEN_INCLUDED
120 
121 // Copyright (c) 2012-2017 DreamWorks Animation LLC
122 // All rights reserved. This software is distributed under the
123 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
Definition: Exceptions.h:87
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:194
#define OPENVDB_DEPRECATED
Definition: Platform.h:49
Definition: Exceptions.h:88
Definition: Exceptions.h:90
IllegalValueException(const std::string &msg) noexcept
Definition: Exceptions.h:100
Definition: Exceptions.h:86
Definition: Exceptions.h:85
IllegalValueException() noexcept
Definition: Exceptions.h:99
Definition: Exceptions.h:89
Exception(const char *eType, const std::string *const msg=nullptr) noexcept
Definition: Exceptions.h:60
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
Definition: Exceptions.h:91
Definition: Exceptions.h:39
Definition: Exceptions.h:97
Exception() noexcept
Definition: Exceptions.h:59
Definition: Exceptions.h:82
Library and file format version numbers.
const char * what() const noexcept override
Definition: Exceptions.h:52
Definition: Exceptions.h:83
Definition: Exceptions.h:43
Definition: Exceptions.h:84
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
#define OPENVDB_EXCEPTION(_classname)
Definition: Exceptions.h:73