OpenVDB: Exceptions.h Source File

OpenVDB 3.2.0

Exceptions.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2016 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 {
40 OPENVDB_USE_VERSION_NAMESPACE
41 namespace OPENVDB_VERSION_NAME {
42
43 class OPENVDB_API Exception: public std::exception
44 {
45 public:
46 virtual const char* what() const throw()
47 {
48 try { return mMessage.c_str(); } catch (...) {};
49 return NULL;
50 }
51
52 virtual ~Exception() throw() {}
53
54 protected:
55 Exception() throw() {}
56 explicit Exception(const char* eType, const std::string* const msg = NULL) throw()
57 {
58 try {
59 if (eType) mMessage = eType;
60 if (msg) mMessage += ": " + (*msg);
61 } catch (...) {}
62 }
63
64 private:
65 std::string mMessage;
66 };
67
68
69 #define OPENVDB_EXCEPTION(_classname) \
70 class OPENVDB_API _classname: public Exception \
71 { \
72 public: \
73 _classname() throw() : Exception( #_classname ) {} \
74 explicit _classname(const std::string &msg) throw() : Exception( #_classname , &msg) {} \
75 }
76
77
78 OPENVDB_EXCEPTION(ArithmeticError);
79 OPENVDB_EXCEPTION(IllegalValueException);
80 OPENVDB_EXCEPTION(IndexError);
81 OPENVDB_EXCEPTION(IoError);
82 OPENVDB_EXCEPTION(KeyError);
83 OPENVDB_EXCEPTION(LookupError);
84 OPENVDB_EXCEPTION(NotImplementedError);
85 OPENVDB_EXCEPTION(ReferenceError);
86 OPENVDB_EXCEPTION(RuntimeError);
87 OPENVDB_EXCEPTION(TypeError);
88 OPENVDB_EXCEPTION(ValueError);
89
90
91 #undef OPENVDB_EXCEPTION
92
93 } // namespace OPENVDB_VERSION_NAME
94 } // namespace openvdb
95
96
97 #define OPENVDB_THROW(exception, message) \
98 { \
99 std::string _openvdb_throw_msg; \
100 try { \
101 std::ostringstream _openvdb_throw_os; \
102 _openvdb_throw_os << message; \
103 _openvdb_throw_msg = _openvdb_throw_os.str(); \
104 } catch (...) {} \
105 throw exception(_openvdb_throw_msg); \
106 } // OPENVDB_THROW
107
108 #endif // OPENVDB_EXCEPTIONS_HAS_BEEN_INCLUDED
109
110 // Copyright (c) 2012-2016 DreamWorks Animation LLC
111 // All rights reserved. This software is distributed under the
112 // 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:195
openvdb::v3_2_0::Exception::Exception
Exception(const char *eType, const std::string *const msg=NULL)
Definition: Exceptions.h:56
openvdb::v3_2_0::ArithmeticError
Definition: Exceptions.h:78
openvdb::v3_2_0::ReferenceError
Definition: Exceptions.h:85
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
Definition: version.h:43
openvdb::v3_2_0::IllegalValueException
Definition: Exceptions.h:79
openvdb::v3_2_0::Exception::~Exception
virtual ~Exception()
Definition: Exceptions.h:52
openvdb::v3_2_0::RuntimeError
Definition: Exceptions.h:86
openvdb
Definition: Exceptions.h:39
openvdb::v3_2_0::Exception::Exception
Exception()
Definition: Exceptions.h:55
openvdb::v3_2_0::Exception
Definition: Exceptions.h:43
version.h
openvdb::v3_2_0::TypeError
Definition: Exceptions.h:87
openvdb::v3_2_0::IoError
Definition: Exceptions.h:81
openvdb::v3_2_0::NotImplementedError
Definition: Exceptions.h:84
openvdb::v3_2_0::ValueError
Definition: Exceptions.h:88
openvdb::v3_2_0::Exception::what
virtual const char * what() const
Definition: Exceptions.h:46
openvdb::v3_2_0::KeyError
Definition: Exceptions.h:82
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
OPENVDB_EXCEPTION
#define OPENVDB_EXCEPTION(_classname)
Definition: Exceptions.h:69
openvdb::v3_2_0::LookupError
Definition: Exceptions.h:83
openvdb::v3_2_0::IndexError
Definition: Exceptions.h:80