Throw all exceptions with Arbutils exception.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string.h>
|
||||
#include "Exception.hpp"
|
||||
|
||||
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
|
||||
|
||||
@@ -10,7 +11,7 @@
|
||||
std::stringstream ss; \
|
||||
ss << "ASSERTION FAILED: [" << __FILENAME__ << " (" << __LINE__ << ")] \""; \
|
||||
ss << #expr << "\""; \
|
||||
throw std::logic_error(ss.str()); \
|
||||
throw ArbUt::Exception(ss.str()); \
|
||||
}
|
||||
#define AssertForEach(iterator, assertion) \
|
||||
{ \
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace ArbUt {
|
||||
[[maybe_unused]] const auto& v = _map.insert({key, value});
|
||||
#ifndef NO_ASSERT
|
||||
if (!v.second)
|
||||
throw std::logic_error("Key already exists");
|
||||
throw ArbUt::Exception("Key already exists");
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
#include "../Exception.hpp"
|
||||
|
||||
namespace ArbUt {
|
||||
template <class ValueT> class List {
|
||||
@@ -27,7 +28,7 @@ namespace ArbUt {
|
||||
if (index >= _vector.size() || index < 0) {
|
||||
std::stringstream ss;
|
||||
ss << "Index " << index << " is out of bounds.";
|
||||
throw std::logic_error(ss.str());
|
||||
throw ArbUt::Exception(ss.str());
|
||||
}
|
||||
#endif
|
||||
return _vector.at(index);
|
||||
@@ -38,7 +39,7 @@ namespace ArbUt {
|
||||
if (index >= _vector.size() || index < 0) {
|
||||
std::stringstream ss;
|
||||
ss << "Index " << index << " is out of bounds.";
|
||||
throw std::logic_error(ss.str());
|
||||
throw ArbUt::Exception(ss.str());
|
||||
}
|
||||
#endif
|
||||
return _vector.at(index);
|
||||
@@ -49,7 +50,7 @@ namespace ArbUt {
|
||||
if (index >= _vector.size() || index < 0) {
|
||||
std::stringstream ss;
|
||||
ss << "Index " << index << " is out of bounds.";
|
||||
throw std::logic_error(ss.str());
|
||||
throw ArbUt::Exception(ss.str());
|
||||
}
|
||||
#endif
|
||||
const auto& prev = _vector.at(index);
|
||||
|
||||
@@ -11,20 +11,20 @@
|
||||
#endif
|
||||
|
||||
namespace ArbUt {
|
||||
class Exception : std::exception {
|
||||
std::string _msg;
|
||||
class Exception : std::logic_error {
|
||||
#if !WINDOWS
|
||||
backward::StackTrace _stack;
|
||||
#endif
|
||||
|
||||
public:
|
||||
explicit Exception(std::string msg) : _msg(std::move(msg)) {
|
||||
explicit Exception(const std::string& msg) : std::logic_error(msg) {
|
||||
#if !WINDOWS
|
||||
_stack.load_here(9);
|
||||
#endif
|
||||
}
|
||||
|
||||
[[nodiscard]] const char* what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_NOTHROW override { return _msg.c_str(); }
|
||||
public:
|
||||
const char* what() const _GLIBCXX_TXN_SAFE_DYN _GLIBCXX_NOTHROW override { return logic_error::what(); }
|
||||
|
||||
[[nodiscard]] std::string GetStacktrace([[maybe_unused]] size_t depth = 6,
|
||||
[[maybe_unused]] bool include_addr = true) const {
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace ArbUt {
|
||||
if (index >= _vector.size()) {
|
||||
std::stringstream ss;
|
||||
ss << "Index " << index << " is out of bounds.";
|
||||
throw std::logic_error(ss.str());
|
||||
throw ArbUt::Exception(ss.str());
|
||||
}
|
||||
#endif
|
||||
return _vector[index];
|
||||
@@ -61,7 +61,7 @@ namespace ArbUt {
|
||||
if (index >= _vector.size()) {
|
||||
std::stringstream ss;
|
||||
ss << "Index " << index << " is out of bounds.";
|
||||
throw std::logic_error(ss.str());
|
||||
throw ArbUt::Exception(ss.str());
|
||||
}
|
||||
#endif
|
||||
delete _vector[index];
|
||||
|
||||
Reference in New Issue
Block a user