24 #ifndef STORAGE_EXCEPTION_H 25 #define STORAGE_EXCEPTION_H 37 #include "storage/Utils/Logger.h" 55 const std::string & func_r,
57 : _file(file_r), _func(func_r), _line(line_r)
64 : _file(), _func(), _line(0)
70 const std::string&
file()
const {
return _file; }
75 const std::string&
func()
const {
return _func; }
80 int line()
const {
return _line; }
103 std::ostream &
operator<<( std::ostream & str,
const CodeLocation & obj );
120 Exception(LogLevel log_level = LogLevel::ERROR);
126 Exception(
const std::string &
msg, LogLevel log_level = LogLevel::ERROR);
143 { _where = newLocation; }
150 const std::string&
msg()
const {
return _msg; }
155 LogLevel log_level()
const {
return _log_level; }
170 static std::string
strErrno(
int errno_r );
175 static std::string
strErrno(
int errno_r,
const std::string &
msg );
183 const char *
const prefix );
190 virtual const char*
what() const noexcept
override {
return _msg.c_str(); }
197 virtual std::ostream&
dumpOn(std::ostream& str)
const;
212 std::ostream & dumpError( std::ostream & str )
const;
220 std::ostream &
operator<<( std::ostream & str,
const Exception & obj );
231 :
Exception(
"Null pointer", LogLevel::ERROR)
271 :
Exception(
"Out of memory", LogLevel::ERROR)
297 const std::string &
msg =
"" )
328 virtual std::ostream&
dumpOn(std::ostream& str)
const override 330 std::string prefix =
msg();
332 if ( prefix.empty() )
333 prefix =
"Index out of range";
335 return str << prefix <<
": " << _invalidIndex
336 <<
" valid: " << _validMin <<
" .. " << _validMax
390 const std::string &
seen,
406 const std::string &
seen()
const {
return _seen; }
411 const std::string &
expected()
const {
return _expected; }
417 virtual std::ostream&
dumpOn(std::ostream& str)
const override 419 std::string prefix =
"Parse error";
421 if ( !
msg().empty() )
424 return str << prefix <<
msg()
425 <<
"; expected: \"" << _expected
426 <<
"\" seen: \"" << _seen <<
"\"" 433 std::string _expected;
CodeLocation()
Default constructor.
Definition: Exception.h:63
static void log(const Exception &exception, const CodeLocation &location, const char *const prefix)
Drop a log line on throw, catch or rethrow.
virtual std::ostream & dumpOn(std::ostream &str) const override
Write proper error message with all relevant data.
Definition: Exception.h:417
Exception class for "index out of range".
Definition: Exception.h:283
Exception class for "overflow".
Definition: Exception.h:351
int validMax() const
Return the valid maximum index.
Definition: Exception.h:320
const std::string & msg() const
Return the message string provided to the constructor.
Definition: Exception.h:150
virtual std::ostream & dumpOn(std::ostream &str) const override
Write proper error message with all relevant data.
Definition: Exception.h:328
virtual const char * what() const noexcept override
Return message string.
Definition: Exception.h:190
const std::string & seen() const
The offending line that caused the parse error.
Definition: Exception.h:406
Exception class for "out of memory".
Definition: Exception.h:267
Exception class for faulty logic within the program.
Definition: Exception.h:255
std::string asString() const
Returns the location in normalized string format.
friend std::ostream & operator<<(std::ostream &str, const CodeLocation &obj)
Stream output.
Helper class for UI exceptions: Store BASE_FILE, FUNCTION and LINE.
Definition: Exception.h:47
ParseException(const std::string &msg, const std::string &seen, const std::string &expected)
Constructor.
Definition: Exception.h:389
Exception class for parse errors, e.g.
Definition: Exception.h:378
virtual std::ostream & dumpOn(std::ostream &str) const
Overload this to print a proper error message.
Definition: Exception.h:442
const std::string & func() const
Returns the name of the function where the exception occured.
Definition: Exception.h:75
const CodeLocation & where() const
Return CodeLocation.
Definition: Exception.h:136
void setMsg(const std::string &msg)
Set a new message string.
Definition: Exception.h:160
int validMin() const
Return the valid minimum index.
Definition: Exception.h:315
Exception class for generic null pointer exceptions.
Definition: Exception.h:227
IndexOutOfRangeException(int invalidIndex, int validMin, int validMax, const std::string &msg="")
Constructor.
Definition: Exception.h:294
std::ostream & operator<<(std::ostream &str, const CodeLocation &obj)
CodeLocation stream output.
Base class for storage exceptions.
Definition: Exception.h:113
std::string asString() const
Error message provided by dumpOn as string.
int line() const
Returns the source line number where the exception occured.
Definition: Exception.h:80
The storage namespace.
Definition: Actiongraph.h:37
void relocate(const CodeLocation &newLocation) const
Exchange location on rethrow.
Definition: Exception.h:142
Exception(LogLevel log_level=LogLevel::ERROR)
Default constructor.
const std::string & file() const
Returns the source file name where the exception occured.
Definition: Exception.h:70
virtual ~ParseException() noexcept
Destructor.
Definition: Exception.h:400
Exception class for unsupported features and operations.
Definition: Exception.h:243
Exception class for IO errors.
Definition: Exception.h:364
int invalidIndex() const
Return the offending index value.
Definition: Exception.h:310
virtual ~Exception() noexcept
Destructor.
const std::string & expected() const
Short textual description of what the parser expected.
Definition: Exception.h:411
CodeLocation(const std::string &file_r, const std::string &func_r, int line_r)
Constructor.
Definition: Exception.h:54
friend std::ostream & operator<<(std::ostream &str, const Exception &obj)
Exception stream output.
static std::string strErrno(int errno_r)
Make a string from errno_r.