diff options
Diffstat (limited to 'include/jau')
-rw-r--r-- | include/jau/basic_types.hpp | 237 | ||||
-rw-r--r-- | include/jau/darray.hpp | 22 | ||||
-rw-r--r-- | include/jau/jni/helper_jni.hpp | 12 | ||||
-rw-r--r-- | include/jau/jni/jni_mem.hpp | 1 | ||||
-rw-r--r-- | include/jau/math/geom/frustum.hpp | 2 | ||||
-rw-r--r-- | include/jau/math/mat4f.hpp | 4 | ||||
-rw-r--r-- | include/jau/math/math_error.hpp | 105 | ||||
-rw-r--r-- | include/jau/math/util/pmvmat4f.hpp | 12 | ||||
-rw-r--r-- | include/jau/ringbuffer.hpp | 2 |
9 files changed, 280 insertions, 117 deletions
diff --git a/include/jau/basic_types.hpp b/include/jau/basic_types.hpp index 85a9883..493492b 100644 --- a/include/jau/basic_types.hpp +++ b/include/jau/basic_types.hpp @@ -26,12 +26,13 @@ #define JAU_BASIC_TYPES_HPP_ #include <cstring> +#include <ios> +#include <ratio> +#include <stdexcept> #include <string> -#include <memory> #include <cstdint> -#include <vector> -#include <type_traits> #include <iostream> +#include <system_error> #include <jau/cpp_lang_util.hpp> #include <jau/packed_attribute.hpp> @@ -306,50 +307,98 @@ namespace jau { class ExceptionBase { private: + // brief message std::string msg_; + // optional whole backtrace std::string backtrace_; + // brief message + optional whole backtrace std::string what_; - protected: - ExceptionBase(std::string type, std::string const& m, const char* file, int line) noexcept; + protected: + ExceptionBase(const std::string &type, std::string const& m, const char* file, int line) noexcept; public: virtual ~ExceptionBase() noexcept = default; - ExceptionBase(const ExceptionBase &o) = default; ExceptionBase(ExceptionBase &&o) = default; ExceptionBase& operator=(const ExceptionBase &o) = default; ExceptionBase& operator=(ExceptionBase &&o) = default; - const std::string& message() const noexcept { return msg_; } + /** Returns brief message. */ + const std::string& brief_message() const noexcept { return msg_; } + /** Returns optional whole backtrace. */ const std::string& backtrace() const noexcept { return backtrace_; } - - /** Allow conversion to `const std::string&`, as required by Catch2's `REQUIRE_THROWS_MATCHES` */ - operator const std::string& () const noexcept { return message(); }; - - virtual const char* what() const noexcept { - return what_.c_str(); // return std::runtime_error::what(); - } + /** Returns brief message and optional whole backtrace, i.e. std::exception::what() string. */ + const std::string& whole_message() const noexcept { return what_; } + + /** Allow conversion to `const std::string&` using brief_message(), as required by Catch2's `REQUIRE_THROWS_MATCHES` */ + operator const std::string& () const noexcept { return brief_message(); }; std::ostream& operator<<(std::ostream& out) noexcept { return out << what_; } + + virtual const char* what() const noexcept { + return whole_message().c_str(); + } + }; + class RuntimeExceptionBase : public ExceptionBase { + protected: + RuntimeExceptionBase(const std::string &type, std::string const& m, const char* file, int line) noexcept + : ExceptionBase(type, m, file, line) {} + + public: + ~RuntimeExceptionBase() noexcept override = default; + + RuntimeExceptionBase(const RuntimeExceptionBase& o) = default; + RuntimeExceptionBase(RuntimeExceptionBase&& o) = default; + RuntimeExceptionBase& operator=(const RuntimeExceptionBase& o) = default; + RuntimeExceptionBase& operator=(RuntimeExceptionBase&& o) = default; }; + class LogicErrorBase : public ExceptionBase { + protected: + LogicErrorBase(const std::string &type, std::string const& m, const char* file, int line) noexcept + : ExceptionBase(type, m, file, line) {} - class OutOfMemoryError : public std::bad_alloc, public ExceptionBase { public: - OutOfMemoryError(std::string const& m, const char* file, int line) - : bad_alloc(), ExceptionBase("OutOfMemoryError", m, file, line) {} + ~LogicErrorBase() noexcept override = default; + + LogicErrorBase(const LogicErrorBase& o) = default; + LogicErrorBase(LogicErrorBase&& o) = default; + LogicErrorBase& operator=(const LogicErrorBase& o) = default; + LogicErrorBase& operator=(LogicErrorBase&& o) = default; + }; + class RuntimeSystemExceptionBase : public RuntimeExceptionBase { + protected: + std::error_code m_ec; + RuntimeSystemExceptionBase(const std::string &type, const std::error_code& ec, std::string const& m, const char* file, int line) noexcept + : RuntimeExceptionBase(type, m, file, line), m_ec(ec) {} + + public: + ~RuntimeSystemExceptionBase() noexcept override = default; + RuntimeSystemExceptionBase(const RuntimeSystemExceptionBase& o) = default; + RuntimeSystemExceptionBase(RuntimeSystemExceptionBase&& o) = default; + RuntimeSystemExceptionBase& operator=(const RuntimeSystemExceptionBase& o) = default; + RuntimeSystemExceptionBase& operator=(RuntimeSystemExceptionBase&& o) = default; + + const std::error_code& code() const noexcept { return m_ec; } + }; + + class OutOfMemoryError : public ExceptionBase, public std::bad_alloc { + public: + OutOfMemoryError(std::string const& m, const char* file, int line) + : ExceptionBase("OutOfMemoryError", m, file, line), bad_alloc() {} + const char* what() const noexcept override { - return ExceptionBase::what(); // return std::runtime_error::what(); + return whole_message().c_str(); } }; - - class RuntimeException : public std::exception, public ExceptionBase { + + class RuntimeException : public RuntimeExceptionBase, public std::runtime_error { protected: - RuntimeException(std::string type, std::string const& m, const char* file, int line) noexcept - : exception(), ExceptionBase(std::move(type), m, file, line) {} + RuntimeException(const std::string &type, std::string const& m, const char* file, int line) noexcept + : RuntimeExceptionBase(type, m, file, line), runtime_error(whole_message()) {} public: RuntimeException(std::string const& m, const char* file, int line) noexcept @@ -361,66 +410,134 @@ namespace jau { RuntimeException(RuntimeException&& o) = default; RuntimeException& operator=(const RuntimeException& o) = default; RuntimeException& operator=(RuntimeException&& o) = default; + + // base class std::exception: + const char* what() const noexcept override { + return whole_message().c_str(); + } + }; + class LogicError : public LogicErrorBase, public std::logic_error { + protected: + LogicError(const std::string &type, std::string const& m, const char* file, int line) noexcept + : LogicErrorBase(type, m, file, line), logic_error(whole_message()) {} + + public: + LogicError(std::string const& m, const char* file, int line) noexcept + : LogicError("LogicErrorStd", m, file, line) {} + + ~LogicError() noexcept override = default; + LogicError(const LogicError& o) = default; + LogicError(LogicError&& o) = default; + LogicError& operator=(const LogicError& o) = default; + LogicError& operator=(LogicError&& o) = default; + const char* what() const noexcept override { - return ExceptionBase::what(); + return whole_message().c_str(); } }; + class RuntimeSystemException : public RuntimeSystemExceptionBase, public std::system_error { + protected: + RuntimeSystemException(const std::string &type, const std::error_code& ec, std::string const& m, const char* file, int line) noexcept + : RuntimeSystemExceptionBase(type, ec, m, file, line), system_error(ec, whole_message()) {} - class InternalError : public RuntimeException { public: - InternalError(std::string const& m, const char* file, int line) noexcept - : RuntimeException("InternalError", m, file, line) {} - }; + RuntimeSystemException(const std::error_code& ec, std::string const& m, const char* file, int line) noexcept + : RuntimeSystemException("RuntimeSystemExceptionStd", ec, m, file, line) {} - class NotImplementedError : public RuntimeException { + ~RuntimeSystemException() noexcept override = default; + + RuntimeSystemException(const RuntimeSystemException& o) = default; + RuntimeSystemException(RuntimeSystemException&& o) = default; + RuntimeSystemException& operator=(const RuntimeSystemException& o) = default; + RuntimeSystemException& operator=(RuntimeSystemException&& o) = default; + + const char* what() const noexcept override { + return whole_message().c_str(); + } + }; + + class IndexOutOfBoundsError : public LogicErrorBase, public std::out_of_range { + protected: + IndexOutOfBoundsError(const char* file, int line, const std::string &type, std::string const& m) noexcept + : LogicErrorBase(type, m, file, line), out_of_range(whole_message()) {} + public: - NotImplementedError(std::string const& m, const char* file, int line) noexcept - : RuntimeException("NotImplementedError", m, file, line) {} + IndexOutOfBoundsError(const std::size_t index, const std::size_t length, const char* file, int line) noexcept + : IndexOutOfBoundsError(file, line, "IndexOutOfBoundsError", "Index "+std::to_string(index)+", data length "+std::to_string(length)) {} + + IndexOutOfBoundsError(const std::string& index_s, const std::string& length_s, const char* file, int line) noexcept + : IndexOutOfBoundsError(file, line, "IndexOutOfBoundsError", "Index "+index_s+", data length "+length_s) {} + + IndexOutOfBoundsError(const std::size_t index, const std::size_t count, const std::size_t length, const char* file, int line) noexcept + : IndexOutOfBoundsError(file, line, "IndexOutOfBoundsError", "Index "+std::to_string(index)+", count "+std::to_string(count)+", data length "+std::to_string(length)) {} + + const char* what() const noexcept override { + return whole_message().c_str(); + } }; - class NullPointerException : public RuntimeException { + class IllegalArgumentError : public LogicErrorBase, public std::invalid_argument { + protected: + IllegalArgumentError(std::string const& type, std::string const& m, const char* file, int line) noexcept + : LogicErrorBase(type, m, file, line), invalid_argument(whole_message()) {} + public: - NullPointerException(std::string const& m, const char* file, int line) noexcept - : RuntimeException("NullPointerException", m, file, line) {} + IllegalArgumentError(std::string const& m, const char* file, int line) noexcept + : IllegalArgumentError("IllegalArgumentError", m, file, line) {} + + const char* what() const noexcept override { + return whole_message().c_str(); + } }; - class IllegalArgumentException : public RuntimeException { + class IllegalStateError : public LogicErrorBase, public std::domain_error { + protected: + IllegalStateError(std::string const& type, std::string const& m, const char* file, int line) noexcept + : LogicErrorBase(type, m, file, line), domain_error(whole_message()) {} + public: - IllegalArgumentException(std::string const& m, const char* file, int line) noexcept - : RuntimeException("IllegalArgumentException", m, file, line) {} + IllegalStateError(std::string const& m, const char* file, int line) noexcept + : IllegalStateError("IllegalStateError", m, file, line) {} + + const char* what() const noexcept override { + return whole_message().c_str(); + } }; - class IllegalStateException : public RuntimeException { + class IOError : public RuntimeSystemExceptionBase, public std::ios_base::failure { public: - IllegalStateException(std::string const& m, const char* file, int line) noexcept - : RuntimeException("IllegalStateException", m, file, line) {} + IOError(std::string const& m, const char* file, int line, const std::error_code& ec = std::io_errc::stream) noexcept + : RuntimeSystemExceptionBase("IOError", ec, m, file, line), failure(whole_message(), ec) {} + + const char* what() const noexcept override { + return whole_message().c_str(); + } }; - class UnsupportedOperationException : public RuntimeException { + class InternalError : public RuntimeException { public: - UnsupportedOperationException(std::string const& m, const char* file, int line) noexcept - : RuntimeException("UnsupportedOperationException", m, file, line) {} + InternalError(std::string const& m, const char* file, int line) noexcept + : RuntimeException("InternalError", m, file, line) {} }; - class IndexOutOfBoundsException : public RuntimeException { + class NotImplementedException : public RuntimeException { public: - IndexOutOfBoundsException(const std::size_t index, const std::size_t length, const char* file, int line) noexcept - : RuntimeException("IndexOutOfBoundsException", "Index "+std::to_string(index)+", data length "+std::to_string(length), file, line) {} - - IndexOutOfBoundsException(const std::string& index_s, const std::string& length_s, const char* file, int line) noexcept - : RuntimeException("IndexOutOfBoundsException", "Index "+index_s+", data length "+length_s, file, line) {} - - IndexOutOfBoundsException(const std::size_t index, const std::size_t count, const std::size_t length, const char* file, int line) noexcept - : RuntimeException("IndexOutOfBoundsException", "Index "+std::to_string(index)+", count "+std::to_string(count)+", data length "+std::to_string(length), file, line) {} + NotImplementedException(std::string const& m, const char* file, int line) noexcept + : RuntimeException("NotImplementedException", m, file, line) {} }; - class IOError : public RuntimeException { + class NullPointerException : public RuntimeException { public: - IOError(std::string const& m, const char* file, int line) noexcept - : RuntimeException("IOError", m, file, line) {} + NullPointerException(std::string const& m, const char* file, int line) noexcept + : RuntimeException("NullPointerException", m, file, line) {} }; + class UnsupportedOperationException : public RuntimeException { + public: + UnsupportedOperationException(std::string const& m, const char* file, int line) noexcept + : RuntimeException("UnsupportedOperationException", m, file, line) {} + }; /** // ************************************************* @@ -436,42 +553,42 @@ namespace jau { inline void set_bit_uint32(const uint8_t nr, uint32_t &mask) { using namespace jau::int_literals; - if( nr > 31 ) { throw IndexOutOfBoundsException(nr, 32, E_FILE_LINE); } + if( nr > 31 ) { throw IndexOutOfBoundsError(nr, 32, E_FILE_LINE); } mask |= 1_u32 << (nr & 31); } inline void clear_bit_uint32(const uint8_t nr, uint32_t &mask) { using namespace jau::int_literals; - if( nr > 31 ) { throw IndexOutOfBoundsException(nr, 32, E_FILE_LINE); } + if( nr > 31 ) { throw IndexOutOfBoundsError(nr, 32, E_FILE_LINE); } mask |= ~(1_u32 << (nr & 31)); } inline uint32_t test_bit_uint32(const uint8_t nr, const uint32_t mask) { using namespace jau::int_literals; - if( nr > 31 ) { throw IndexOutOfBoundsException(nr, 32, E_FILE_LINE); } + if( nr > 31 ) { throw IndexOutOfBoundsError(nr, 32, E_FILE_LINE); } return mask & (1_u32 << (nr & 31)); } inline void set_bit_uint64(const uint8_t nr, uint64_t &mask) { using namespace jau::int_literals; - if( nr > 63 ) { throw IndexOutOfBoundsException(nr, 64, E_FILE_LINE); } + if( nr > 63 ) { throw IndexOutOfBoundsError(nr, 64, E_FILE_LINE); } mask |= 1_u64 << (nr & 63); } inline void clear_bit_uint64(const uint8_t nr, uint64_t &mask) { using namespace jau::int_literals; - if( nr > 63 ) { throw IndexOutOfBoundsException(nr, 64, E_FILE_LINE); } + if( nr > 63 ) { throw IndexOutOfBoundsError(nr, 64, E_FILE_LINE); } mask |= ~(1_u64 << (nr & 63)); } inline uint64_t test_bit_uint64(const uint8_t nr, const uint64_t mask) { using namespace jau::int_literals; - if( nr > 63 ) { throw IndexOutOfBoundsException(nr, 64, E_FILE_LINE); } + if( nr > 63 ) { throw IndexOutOfBoundsError(nr, 64, E_FILE_LINE); } return mask & (1_u64 << (nr & 63)); } diff --git a/include/jau/darray.hpp b/include/jau/darray.hpp index 7ad869b..279914a 100644 --- a/include/jau/darray.hpp +++ b/include/jau/darray.hpp @@ -204,7 +204,7 @@ namespace jau { constexpr value_type * allocStore(const size_type size_) { if( 0 != size_ ) { if( size_ > DIFF_MAX ) { - throw jau::IllegalArgumentException("alloc "+std::to_string(size_)+" > difference_type max "+ + throw jau::IllegalArgumentError("alloc "+std::to_string(size_)+" > difference_type max "+ std::to_string(DIFF_MAX), E_FILE_LINE); } value_type * m = alloc_inst.allocate(size_); @@ -327,7 +327,7 @@ In copy constructor ‘std::__shared_count<_Lp>::__shared_count(const std::__sha constexpr void ctor_copy_range_check(pointer dest, iterator first, const_iterator last) { JAU_DARRAY_PRINTF0("ctor_copy_range_check [%zd .. %zd] -> ??, dist %zd\n", (first-begin_), (last-begin_)-1, (last-first)-1); if( first > last ) { - throw jau::IllegalArgumentException("first "+to_hexstring(first)+" > last "+to_hexstring(last), E_FILE_LINE); + throw jau::IllegalArgumentError("first "+to_hexstring(first)+" > last "+to_hexstring(last), E_FILE_LINE); } for(; first < last; ++dest, ++first) { new (const_cast<pointer_mutable>(dest)) value_type( *first ); // placement new @@ -336,7 +336,7 @@ In copy constructor ‘std::__shared_count<_Lp>::__shared_count(const std::__sha constexpr pointer clone_range_check(const size_type dest_capacity, iterator first, const_iterator last) { JAU_DARRAY_PRINTF0("clone_range_check [%zd .. %zd], count %zd -> %d\n", (first-begin_), (last-begin_)-1, (last-first)-1, (int)dest_capacity); if( dest_capacity < size_type(last-first) ) { - throw jau::IllegalArgumentException("capacity "+std::to_string(dest_capacity)+" < source range "+ + throw jau::IllegalArgumentError("capacity "+std::to_string(dest_capacity)+" < source range "+ std::to_string(difference_type(last-first)), E_FILE_LINE); } pointer dest = allocStore(dest_capacity); @@ -347,7 +347,7 @@ In copy constructor ‘std::__shared_count<_Lp>::__shared_count(const std::__sha template< class InputIt > constexpr static void ctor_copy_range_foreign(pointer dest, InputIt first, InputIt last) { if( first > last ) { - throw jau::IllegalArgumentException("first "+jau::to_string( first )+" > last "+ + throw jau::IllegalArgumentError("first "+jau::to_string( first )+" > last "+ jau::to_string( last ), E_FILE_LINE); } for(; first != last; ++dest, ++first) { @@ -357,7 +357,7 @@ In copy constructor ‘std::__shared_count<_Lp>::__shared_count(const std::__sha template< class InputIt > constexpr pointer clone_range_foreign(const size_type dest_capacity, InputIt first, InputIt last) { if( dest_capacity < size_type(last-first) ) { - throw jau::IllegalArgumentException("capacity "+std::to_string(dest_capacity)+" < source range "+ + throw jau::IllegalArgumentError("capacity "+std::to_string(dest_capacity)+" < source range "+ std::to_string(difference_type(last-first)), E_FILE_LINE); } pointer dest = allocStore(dest_capacity); @@ -803,7 +803,7 @@ In copy constructor ‘std::__shared_count<_Lp>::__shared_count(const std::__sha if( 0 <= i && i < size() ) { return *(begin_+i); } - throw jau::IndexOutOfBoundsException(i, size(), E_FILE_LINE); + throw jau::IndexOutOfBoundsError(i, size(), E_FILE_LINE); } /** @@ -813,7 +813,7 @@ In copy constructor ‘std::__shared_count<_Lp>::__shared_count(const std::__sha if( 0 <= i && i < size() ) { return *(begin_+i); } - throw jau::IndexOutOfBoundsException(i, size(), E_FILE_LINE); + throw jau::IndexOutOfBoundsError(i, size(), E_FILE_LINE); } // write access, mutable array operations @@ -997,7 +997,7 @@ In copy constructor ‘std::__shared_count<_Lp>::__shared_count(const std::__sha return begin_ <= pos && pos <= end_ ? const_cast<iterator>(pos) : end_; } else { - throw jau::IndexOutOfBoundsException(std::to_string(difference_type(pos - begin_)), std::to_string(size()), E_FILE_LINE); + throw jau::IndexOutOfBoundsError(std::to_string(difference_type(pos - begin_)), std::to_string(size()), E_FILE_LINE); } } @@ -1038,7 +1038,7 @@ In copy constructor ‘std::__shared_count<_Lp>::__shared_count(const std::__sha return begin_ <= pos_new && pos_new <= end_ ? pos_new : end_; } else { - throw jau::IndexOutOfBoundsException(std::to_string(difference_type(pos - begin_)), std::to_string(size()), E_FILE_LINE); + throw jau::IndexOutOfBoundsError(std::to_string(difference_type(pos - begin_)), std::to_string(size()), E_FILE_LINE); } } @@ -1071,7 +1071,7 @@ In copy constructor ‘std::__shared_count<_Lp>::__shared_count(const std::__sha return begin_ <= pos_new && pos_new <= end_ ? pos_new : end_; } else { - throw jau::IndexOutOfBoundsException(std::to_string(difference_type(pos - begin_)), std::to_string(size()), E_FILE_LINE); + throw jau::IndexOutOfBoundsError(std::to_string(difference_type(pos - begin_)), std::to_string(size()), E_FILE_LINE); } } @@ -1101,7 +1101,7 @@ In copy constructor ‘std::__shared_count<_Lp>::__shared_count(const std::__sha return begin_ <= pos_new && pos_new <= end_ ? pos_new : end_; } else { - throw jau::IndexOutOfBoundsException(std::to_string(difference_type(pos - begin_)), std::to_string(size()), E_FILE_LINE); + throw jau::IndexOutOfBoundsError(std::to_string(difference_type(pos - begin_)), std::to_string(size()), E_FILE_LINE); } } diff --git a/include/jau/jni/helper_jni.hpp b/include/jau/jni/helper_jni.hpp index 0ee3f75..36247cb 100644 --- a/include/jau/jni/helper_jni.hpp +++ b/include/jau/jni/helper_jni.hpp @@ -76,21 +76,23 @@ namespace jau::jni { void java_exception_check_and_throw(JNIEnv *env, const char* file, int line); void print_native_caught_exception_fwd2java(const jau::OutOfMemoryError &e, const char* file, int line); - void print_native_caught_exception_fwd2java(const jau::RuntimeException &e, const char* file, int line); + void print_native_caught_exception_fwd2java(const jau::LogicErrorBase &e, const char* file, int line); + void print_native_caught_exception_fwd2java(const jau::RuntimeExceptionBase &e, const char* file, int line); void print_native_caught_exception_fwd2java(const std::exception &e, const char* file, int line); void print_native_caught_exception_fwd2java(const std::string &msg, const char* file, int line); void print_native_caught_exception_fwd2java(const char * cmsg, const char* file, int line); void raise_java_exception(JNIEnv *env, const std::exception &e, const char* file, int line); void raise_java_exception(JNIEnv *env, const std::runtime_error &e, const char* file, int line); - void raise_java_exception(JNIEnv *env, const jau::RuntimeException &e, const char* file, int line); + void raise_java_exception(JNIEnv *env, const jau::LogicErrorBase &e, const char* file, int line); + void raise_java_exception(JNIEnv *env, const jau::RuntimeExceptionBase &e, const char* file, int line); void raise_java_exception(JNIEnv *env, const jau::InternalError &e, const char* file, int line); void raise_java_exception(JNIEnv *env, const jau::NullPointerException &e, const char* file, int line); - void raise_java_exception(JNIEnv *env, const jau::IllegalArgumentException &e, const char* file, int line); + void raise_java_exception(JNIEnv *env, const jau::IllegalArgumentError &e, const char* file, int line); void raise_java_exception(JNIEnv *env, const std::invalid_argument &e, const char* file, int line); - void raise_java_exception(JNIEnv *env, const jau::IllegalStateException &e, const char* file, int line); + void raise_java_exception(JNIEnv *env, const jau::IllegalStateError &e, const char* file, int line); void raise_java_exception(JNIEnv *env, const jau::UnsupportedOperationException &e, const char* file, int line); - void raise_java_exception(JNIEnv *env, const jau::IndexOutOfBoundsException &e, const char* file, int line); + void raise_java_exception(JNIEnv *env, const jau::IndexOutOfBoundsError &e, const char* file, int line); void raise_java_exception(JNIEnv *env, const std::bad_alloc &e, const char* file, int line); void raise_java_exception(JNIEnv *env, const jau::OutOfMemoryError &e, const char* file, int line); diff --git a/include/jau/jni/jni_mem.hpp b/include/jau/jni/jni_mem.hpp index 5fca3f1..378a42c 100644 --- a/include/jau/jni/jni_mem.hpp +++ b/include/jau/jni/jni_mem.hpp @@ -30,7 +30,6 @@ #define JAU_JNIMEM__HPP_ #include <jni.h> -#include <stdexcept> #include <mutex> #include <jau/basic_types.hpp> diff --git a/include/jau/math/geom/frustum.hpp b/include/jau/math/geom/frustum.hpp index d6452fa..e516efb 100644 --- a/include/jau/math/geom/frustum.hpp +++ b/include/jau/math/geom/frustum.hpp @@ -127,7 +127,7 @@ class Frustum { : fovhv(fovhv_), zNear(zNear_), zFar(zFar_) { if( zNear <= 0.0f || zFar <= zNear ) { - throw IllegalArgumentException("Requirements zNear > 0 and zFar > zNear, but zNear "+std::to_string(zNear)+", zFar "+std::to_string(zFar), E_FILE_LINE); + throw IllegalArgumentError("Requirements zNear > 0 and zFar > zNear, but zNear "+std::to_string(zNear)+", zFar "+std::to_string(zFar), E_FILE_LINE); } } diff --git a/include/jau/math/mat4f.hpp b/include/jau/math/mat4f.hpp index a0bc107..f016f3a 100644 --- a/include/jau/math/mat4f.hpp +++ b/include/jau/math/mat4f.hpp @@ -1203,10 +1203,10 @@ class alignas(Value_type) Matrix4 { const value_type bottom, const value_type top, const value_type zNear, const value_type zFar) { if( zNear <= zero || zFar <= zNear ) { - throw jau::IllegalArgumentException("Requirements zNear > 0 and zFar > zNear, but zNear "+std::to_string(zNear)+", zFar "+std::to_string(zFar), E_FILE_LINE); + throw jau::IllegalArgumentError("Requirements zNear > 0 and zFar > zNear, but zNear "+std::to_string(zNear)+", zFar "+std::to_string(zFar), E_FILE_LINE); } if( left == right || top == bottom) { - throw jau::IllegalArgumentException("GL_INVALID_VALUE: top,bottom and left,right must not be equal", E_FILE_LINE); + throw jau::IllegalArgumentError("GL_INVALID_VALUE: top,bottom and left,right must not be equal", E_FILE_LINE); } { // m00 = m11 = m22 = m33 = 1f; diff --git a/include/jau/math/math_error.hpp b/include/jau/math/math_error.hpp index fdd496f..4ecf3f5 100644 --- a/include/jau/math/math_error.hpp +++ b/include/jau/math/math_error.hpp @@ -43,62 +43,107 @@ namespace jau::math { */ /** Error types as specified by [C++ Math Error Handling](https://en.cppreference.com/w/cpp/numeric/math/math_errhandling) */ - enum class math_error_t { - /** See FE_INVALID */ + enum class math_error_t : uint16_t { + /** no math error */ + none = 0, + /** See FE_INVALID, i.e. MathDomainError, std::domain_error : std::logic_error */ invalid, - /** See FE_DIVBYZERO */ + /** See FE_DIVBYZERO, i.e. MathDivByZeroError, std::domain_error : std::logic_error*/ div_by_zero, - /** See FE_OVERFLOW */ + /** See FE_OVERFLOW, i.e. MathOverflowError, std::overflow_error : std::runtime_error */ overflow, - /** See FE_UNDERFLOW */ + /** See FE_UNDERFLOW, i.e. MathUnderflowError, std::underflow_error : std::runtime_error */ underflow, - /** See FE_INEXACT */ - inexact + /** See FE_INEXACT, i.e. MathInexactError, std::runtime_error */ + inexact, + /** undefined math error */ + undefined = 1U << 15, }; /** Returns std::string representation of math_error_t */ std::string to_string(const math_error_t v) noexcept; - class MathError : public RuntimeException { + class MathErrorBase : public ExceptionBase { private: math_error_t m_error; - public: - MathError(math_error_t err, std::string const& m, const char* file, int line) noexcept - : RuntimeException("MathError("+to_string(err)+")", m, file, line), m_error(err) {} - - math_error_t error() const noexcept; + protected: + MathErrorBase(math_error_t err, std::string const& m, const char* file, int line) noexcept + : ExceptionBase("MathError("+to_string(err)+")", m, file, line), m_error(err) {} + + public: + math_error_t error() const noexcept; }; - /** math_error_t::invalid */ - class MathDomainError : public MathError { + class MathRuntimeErrorBase : public MathErrorBase { + protected: + MathRuntimeErrorBase(math_error_t err, std::string const& m, const char* file, int line) noexcept + : MathErrorBase(err, m, file, line) {} + }; + + class MathError : public MathErrorBase, public std::exception { public: - MathDomainError(std::string const& m, const char* file, int line) noexcept - : MathError(math_error_t::invalid, m, file, line) {} + MathError(math_error_t err, std::string const& m, const char* file, int line) noexcept + : MathErrorBase(err, m, file, line), exception() {} + + const char* what() const noexcept override { + return whole_message().c_str(); + } }; - /** math_error_t::div_by_zero, i.e. pole error */ - class MathDivByZeroError : public MathError { + + /** math_error_t::inexact */ + class MathInexactError : public MathRuntimeErrorBase, public std::runtime_error { public: - MathDivByZeroError(std::string const& m, const char* file, int line) noexcept - : MathError(math_error_t::div_by_zero, m, file, line) {} + MathInexactError(std::string const& m, const char* file, int line) noexcept + : MathRuntimeErrorBase(math_error_t::inexact, m, file, line), runtime_error(whole_message()) {} + + const char* what() const noexcept override { + return whole_message().c_str(); + } }; + /** math_error_t::overflow */ - class MathOverflowError : public MathError { + class MathOverflowError : public MathRuntimeErrorBase, public std::overflow_error { public: MathOverflowError(std::string const& m, const char* file, int line) noexcept - : MathError(math_error_t::overflow, m, file, line) {} + : MathRuntimeErrorBase(math_error_t::overflow, m, file, line), overflow_error(whole_message()) {} + + const char* what() const noexcept override { + return whole_message().c_str(); + } }; + /** math_error_t::underflow */ - class MathUnderflowError : public MathError { + class MathUnderflowError : public MathRuntimeErrorBase, public std::underflow_error { public: MathUnderflowError(std::string const& m, const char* file, int line) noexcept - : MathError(math_error_t::underflow, m, file, line) {} + : MathRuntimeErrorBase(math_error_t::underflow, m, file, line), underflow_error(whole_message()) {} + + const char* what() const noexcept override { + return whole_message().c_str(); + } }; - /** math_error_t::inexact */ - class MathInexactError : public MathError { + + /** math_error_t::invalid */ + class MathDomainError : public MathErrorBase, public std::domain_error { + protected: + MathDomainError(math_error_t err, std::string const& m, const char* file, int line) noexcept + : MathErrorBase(err, m, file, line), domain_error(whole_message()) {} + public: - MathInexactError(std::string const& m, const char* file, int line) noexcept - : MathError(math_error_t::inexact, m, file, line) {} + MathDomainError(std::string const& m, const char* file, int line) noexcept + : MathErrorBase(math_error_t::invalid, m, file, line), domain_error(whole_message()) {} + + const char* what() const noexcept override { + return whole_message().c_str(); + } }; - + + /** math_error_t::div_by_zero, i.e. pole error */ + class MathDivByZeroError : public MathDomainError { + public: + MathDivByZeroError(std::string const& m, const char* file, int line) noexcept + : MathDomainError(math_error_t::div_by_zero, m, file, line) {} + }; + /**@}*/ } // namespace jau diff --git a/include/jau/math/util/pmvmat4f.hpp b/include/jau/math/util/pmvmat4f.hpp index 3073ea3..f4cc846 100644 --- a/include/jau/math/util/pmvmat4f.hpp +++ b/include/jau/math/util/pmvmat4f.hpp @@ -329,7 +329,7 @@ class PMVMatrix4 { */ Mat4& getMvi() { if( 0 == ( INVERSE_MODELVIEW & requestBits ) ) { // FIXME - throw jau::IllegalArgumentException("Not requested in ctor", E_FILE_LINE); + throw jau::IllegalArgumentError("Not requested in ctor", E_FILE_LINE); } updateImpl(false); return matMvi; @@ -344,7 +344,7 @@ class PMVMatrix4 { */ SyncMat4& getSyncMvi() { if( 0 == ( INVERSE_MODELVIEW & requestBits ) ) { // FIXME - throw jau::IllegalArgumentException("Not requested in ctor", E_FILE_LINE); + throw jau::IllegalArgumentError("Not requested in ctor", E_FILE_LINE); } return syncMvi; } @@ -358,7 +358,7 @@ class PMVMatrix4 { */ Mat4& getMvit() { if( 0 == ( INVERSE_TRANSPOSED_MODELVIEW & requestBits ) ) { // FIXME - throw jau::IllegalArgumentException("Not requested in ctor", E_FILE_LINE); + throw jau::IllegalArgumentError("Not requested in ctor", E_FILE_LINE); } updateImpl(false); return matMvit; @@ -373,7 +373,7 @@ class PMVMatrix4 { */ SyncMat4& getSyncMvit() { if( 0 == ( INVERSE_TRANSPOSED_MODELVIEW & requestBits ) ) { // FIXME - throw jau::IllegalArgumentException("Not requested in ctor", E_FILE_LINE); + throw jau::IllegalArgumentError("Not requested in ctor", E_FILE_LINE); } return syncMvit; } @@ -387,7 +387,7 @@ class PMVMatrix4 { */ SyncMats4f& getSyncPMvMvi() { if( 0 == ( INVERSE_MODELVIEW & requestBits ) ) { // FIXME - throw jau::IllegalArgumentException("Not requested in ctor", E_FILE_LINE); + throw jau::IllegalArgumentError("Not requested in ctor", E_FILE_LINE); } return syncP_Mv_Mvi; } @@ -401,7 +401,7 @@ class PMVMatrix4 { */ SyncMats4f& getSyncPMvMviMvit() { if( 0 == ( INVERSE_TRANSPOSED_MODELVIEW & requestBits ) ) { // FIXME - throw jau::IllegalArgumentException("Not requested in ctor", E_FILE_LINE); + throw jau::IllegalArgumentError("Not requested in ctor", E_FILE_LINE); } return syncP_Mv_Mvi_Mvit; } diff --git a/include/jau/ringbuffer.hpp b/include/jau/ringbuffer.hpp index b808007..85468f8 100644 --- a/include/jau/ringbuffer.hpp +++ b/include/jau/ringbuffer.hpp @@ -976,7 +976,7 @@ class ringbuffer { return; } if( size_ > newCapacity ) { - throw IllegalArgumentException("amount "+std::to_string(newCapacity)+" < size, "+toString(), E_FILE_LINE); + throw IllegalArgumentError("amount "+std::to_string(newCapacity)+" < size, "+toString(), E_FILE_LINE); } // save current data |