17 #ifndef COM_BORA_SOFTWARE__BALAU_EXCEPTION__BALAU_EXCEPTION 18 #define COM_BORA_SOFTWARE__BALAU_EXCEPTION__BALAU_EXCEPTION 23 #ifdef BALAU_ENABLE_STACKTRACES 24 #include <boost/stacktrace.hpp> 26 #include <Balau/Util/Impl/StringsImpl.hpp> 28 #define _ThrowBalauException_generateStackTrace \ 29 std::ostringstream stStream; \ 30 stStream << boost::stacktrace::stacktrace(); \ 31 std::string st = stStream.str(); \ 32 std::string match = std::string(BalauString(BALAU_BASE_FOLDER_)) + "/"; \ 33 std::string replacement; \ 34 ::Balau::Util::Impl::replaceAllImpl(st, match, replacement, nullptr); 36 #define _ThrowBalauException_generateStackTrace std::string st; 45 #define ThrowBalauException(ExceptionClass, ...) { \ 46 _ThrowBalauException_generateStackTrace \ 47 throw ExceptionClass(__FILE__, __LINE__, st, __VA_ARGS__); \ 48 } _Balau_SwallowSemiColon_() 66 public:
const char * what() const noexcept
override {
67 return fullMessage.c_str();
72 const std::string & st,
73 const std::string & name,
74 const std::string & text)
76 ,
fullMessage(generateFullMessage(file, line, st, name, text)) {}
78 private:
static std::string generateFullMessage(
const char * file,
80 const std::string & st,
81 const std::string & name,
82 const std::string & text) {
83 std::ostringstream stream;
84 stream << stripFilePath(file) <<
":" << line <<
" - " << name <<
" - " << text;
94 private:
static std::string stripFilePath(
const char * file) {
95 const char * lastForward = strrchr(file,
'/');
97 if (lastForward !=
nullptr) {
98 return std::string(lastForward + 1);
121 template <
typename AllocatorT>
147 public:
IllegalStateException(
const char * file,
int line,
const std::string & st,
const std::string & text)
171 public:
ConversionException(
const char * file,
int line,
const std::string & st,
const std::string & text)
179 public:
BugException(
const char * file,
int line,
const std::string & st,
const std::string & text)
188 inline std::string
toString(
const std::exception & e) {
195 template <
typename AllocatorT>
197 return toString<AllocatorT>(e.what());
200 #endif // COM_BORA_SOFTWARE__BALAU_EXCEPTION__BALAU_EXCEPTION bool operator==(const BalauException &lhs, const BalauException &rhs)
Base class comparison function for Balau exceptions.
Definition: BalauException.hpp:112
All exception classes.
Definition: BalauException.hpp:50
Pre-defined universal to-string functions.
Balau::U8String< AllocatorT > toString(const BalauException &e)
Base class toString<AllocatorT> function for Balau exceptions.
Definition: BalauException.hpp:122
Thrown when a feature is not yet implemented.
Definition: BalauException.hpp:162
Thrown when a bug is encountered (mainly unimplemented switch cases).
Definition: BalauException.hpp:178
Thrown when an illegal argument is passed to a function or method.
Definition: BalauException.hpp:138
const std::string fullMessage
The full message (includes file and line information).
Definition: BalauException.hpp:64
Thrown when a conversion fails.
Definition: BalauException.hpp:170
const std::string message
The message.
Definition: BalauException.hpp:59
std::basic_string< char, std::char_traits< char >, AllocatorT > U8String
UTF-8 string type with selectable allocator.
Definition: ToStringA.hpp:41
Thrown when a variable is not in a valid state or when a section of code has been executed at an inap...
Definition: BalauException.hpp:146
Base class of all Balau exceptions.
Definition: BalauException.hpp:55
Thrown when an operation is deliberately not implemented.
Definition: BalauException.hpp:154