11 #define throw_ Exception::Raiser() ^ Exception::Source(__FUNC__, __FILE__, __LINE__) <<
13 #define throw_ Exception::Raiser() ^
17 #define EXCEPTION(Class) \
18 typedef SharedPtr<Class> Ptr; \
19 typedef SharedPtr<const Class> ConstPtr; \
21 virtual Exception::Ptr clone() const { return new Class(*this); } \
22 virtual String typeName() const { return typeid(*this).name(); } \
23 virtual void raise() const { throw *this; } \
78 void operator^(
const ostream& os) {
auto& ms =
static_cast<const MsgStream&
>(os);
assert(ms.e); ms.e->_message += ms.str(); ms.e->raise(); }
86 _source = rhs._source;
87 _message = rhs._message;
100 const char*
what()
const throw() { cacheWhat();
return _what->c_str(); }
116 sout() <<
message() <<
" (exception: " << typeName() <<
"; " <<
source() <<
")" :
121 void cacheWhat()
const {
if (!_what) _what = honey::make_unique<std::string>(
createWhat()); }
125 mutable UniquePtr<std::string> _what;
138 Std(
const T& e) : _e(e) { *
this << _e.what(); }
140 virtual Exception::Ptr
clone()
const {
return new Std(_e); }
142 virtual void raise()
const {
throw _e; }
158 catch (
Exception& e) {
return e.clone(); }
int line
Definition: Exception.h:71
SharedPtr< Std > Ptr
Definition: Exception.h:135
Thrown on debug assert() failure.
Definition: Exception.h:180
const char * file
Definition: Exception.h:70
Combined intrusive/non-intrusive smart pointer. Can reference and share any object automatically...
Definition: SharedPtr.h:175
Std< T >::Ptr createStd(const T &e)
Definition: Exception.h:149
Level debug(nullptr,"debug")
Low-level information for debugging purposes.
Definition: Log.h:26
const Char * c_str(const Char *str)
Ensures that str points to a valid C-string. If str is null then the result is an empty C-string (ie...
Definition: String.h:159
Info about source where exception was thrown.
Definition: Exception.h:57
Source()
Definition: Exception.h:59
Reference-counted object for intrusive shared pointers.
Definition: SharedPtr.h:93
virtual Exception::Ptr clone() const
Definition: Exception.h:140
friend ostream & operator<<(ostream &os, const Exception &e)
Definition: Exception.h:109
Definition: Exception.h:151
Wrapper around std exception to allow for polymorphic throw.
Definition: Exception.h:133
#define EXCEPTION(Class)
Declares methods required for every subclass of honey::Exception.
Definition: Exception.h:17
Exception(const Exception &rhs)
Definition: Exception.h:82
ostringstream sout()
Shorthand to create ostringstream.
Definition: Stream.h:15
const Source & source() const
Get info about source where exception was thrown.
Definition: Exception.h:95
#define assert(...)
Forwards to assert_#args. See assert_1(), assert_2().
Definition: Debug.h:24
friend ostream & operator<<(ostream &os, const Source &source)
Definition: Exception.h:64
Unicode UTF-16 string class, wrapper around std::u16string.
Definition: String.h:23
Exception * e
Definition: Exception.h:53
Base exception class. Exceptions inherited from this class provide debug info and can be thrown polym...
Definition: Exception.h:45
void operator^(const Exception &e)
Definition: Exception.h:77
MsgStream(MsgStream &&rhs)
Definition: Exception.h:52
virtual String typeName() const
Definition: Exception.h:141
const String & message() const
Get custom error message. The error message can be appended to using global operator<<(Exception, String)
Definition: Exception.h:97
Exception & operator<<(Exception &e)
Definition: Exception.h:61
void operator^(const ostream &os)
Definition: Exception.h:78
MsgStream(Exception &e)
Definition: Exception.h:51
Exception & operator=(const Exception &rhs)
Definition: Exception.h:84
const char * func
Definition: Exception.h:69
Std(const T &e)
Definition: Exception.h:138
static Ptr current()
Create a clone of the current exception caught with (...)
Definition: Exception.h:154
MsgStream operator<<(T &&val)
Append custom error message.
Definition: Exception.h:107
Helper to raise an exception after the right side of ^ has been evaluated.
Definition: Exception.h:75
Global Honeycomb namespace.
SharedPtr< const Std > ConstPtr
Definition: Exception.h:136
Custom error message builder.
Definition: Exception.h:49
Exception && operator<<(Exception &&e)
Definition: Exception.h:62
virtual String createWhat() const
Create what message. Called only on demand and result is cached.
Definition: Exception.h:113
const char * what() const
Get full diagnostic message.
Definition: Exception.h:100
Source(const char *func, const char *file, int line)
Definition: Exception.h:60