Loading...
Searching...
No Matches
Exceptions.h
Go to the documentation of this file.
// Copyright Contributors to the OpenVDB Project
// SPDX-License-Identifier: MPL-2.0
#ifndef OPENVDB_EXCEPTIONS_HAS_BEEN_INCLUDED
#define OPENVDB_EXCEPTIONS_HAS_BEEN_INCLUDED
#include "version.h"
#include <exception>
#include <sstream>
#include <string>
namespace openvdb {
OPENVDB_USE_VERSION_NAMESPACE
namespace OPENVDB_VERSION_NAME {
class OPENVDB_API Exception: public std::exception
{
public:
Exception(const Exception&) = default;
Exception(Exception&&) = default;
Exception& operator=(const Exception&) = default;
Exception& operator=(Exception&&) = default;
~Exception() override = default;
const char* what() const noexcept override
{
try { return mMessage.c_str(); } catch (...) {}
return nullptr;
}
protected:
Exception() noexcept {}
explicit Exception(const char* eType, const std::string* const msg = nullptr) noexcept
{
try {
if (eType) mMessage = eType;
if (msg) mMessage += ": " + (*msg);
} catch (...) {}
}
private:
std::string mMessage;
};
#define OPENVDB_EXCEPTION(_classname) \
class OPENVDB_API _classname: public Exception \
{ \
public: \
_classname() noexcept: Exception( #_classname ) {} \
explicit _classname(const std::string& msg) noexcept: Exception( #_classname , &msg) {} \
}
OPENVDB_EXCEPTION(ArithmeticError);
OPENVDB_EXCEPTION(IndexError);
OPENVDB_EXCEPTION(IoError);
OPENVDB_EXCEPTION(KeyError);
OPENVDB_EXCEPTION(LookupError);
OPENVDB_EXCEPTION(NotImplementedError);
OPENVDB_EXCEPTION(ReferenceError);
OPENVDB_EXCEPTION(RuntimeError);
OPENVDB_EXCEPTION(TypeError);
OPENVDB_EXCEPTION(ValueError);
#undef OPENVDB_EXCEPTION
} // namespace OPENVDB_VERSION_NAME
} // namespace openvdb
#define OPENVDB_THROW(exception, message) \
{ \
std::string _openvdb_throw_msg; \
try { \
std::ostringstream _openvdb_throw_os; \
_openvdb_throw_os << message; \
_openvdb_throw_msg = _openvdb_throw_os.str(); \
} catch (...) {} \
throw exception(_openvdb_throw_msg); \
} // OPENVDB_THROW
#endif // OPENVDB_EXCEPTIONS_HAS_BEEN_INCLUDED
OPENVDB_API
#define OPENVDB_API
Definition Platform.h:251
openvdb::v10_0::ArithmeticError::ArithmeticError
ArithmeticError() noexcept
Definition Exceptions.h:56
openvdb::v10_0::Exception::Exception
Exception() noexcept
Definition Exceptions.h:33
openvdb::v10_0::Exception::Exception
Exception(const char *eType, const std::string *const msg=nullptr) noexcept
Definition Exceptions.h:34
openvdb::v10_0::Exception::Exception
Exception(Exception &&)=default
openvdb::v10_0::Exception::operator=
Exception & operator=(const Exception &)=default
openvdb::v10_0::Exception::what
const char * what() const noexcept override
Definition Exceptions.h:26
openvdb::v10_0::Exception::operator=
Exception & operator=(Exception &&)=default
openvdb::v10_0::Exception::Exception
Exception(const Exception &)=default
openvdb::v10_0::Exception::~Exception
~Exception() override=default
openvdb::v10_0::IndexError::IndexError
IndexError() noexcept
Definition Exceptions.h:57
openvdb::v10_0::IoError::IoError
IoError() noexcept
Definition Exceptions.h:58
openvdb::v10_0::KeyError::KeyError
KeyError() noexcept
Definition Exceptions.h:59
openvdb::v10_0::LookupError::LookupError
LookupError() noexcept
Definition Exceptions.h:60
openvdb::v10_0::NotImplementedError::NotImplementedError
NotImplementedError() noexcept
Definition Exceptions.h:61
openvdb::v10_0::ReferenceError::ReferenceError
ReferenceError() noexcept
Definition Exceptions.h:62
openvdb::v10_0::RuntimeError::RuntimeError
RuntimeError() noexcept
Definition Exceptions.h:63
openvdb::v10_0::TypeError::TypeError
TypeError() noexcept
Definition Exceptions.h:64
openvdb::v10_0::ValueError::ValueError
ValueError() noexcept
Definition Exceptions.h:65
openvdb
Definition Exceptions.h:13
OPENVDB_EXCEPTION
#define OPENVDB_EXCEPTION(_classname)
Definition Exceptions.h:47
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:212