24#ifndef STORAGE_EXCEPTION_H
25#define STORAGE_EXCEPTION_H
37#include "storage/Utils/Logger.h"
38#include "storage/Utils/Swig.h"
57 const std::string & func_r,
59 : _file(file_r), _func(func_r), _line(line_r)
66 : _file(), _func(), _line(0)
72 const std::string&
file()
const {
return _file; }
77 const std::string&
func()
const {
return _func; }
82 int line()
const {
return _line; }
89 std::string asString() const ST_DEPRECATED;
94 friend std::ostream & operator<<( std::ostream & str, const
CodeLocation & obj );
108 std::ostream & operator<<( std::ostream & str, const
CodeLocation & obj );
149 { _where = newLocation; }
156 const std::string&
msg()
const {
return _msg; }
161 LogLevel log_level()
const {
return _log_level; }
173 std::string asString() const ST_DEPRECATED;
183 static std::
string strErrno(
int errno_r, const std::
string &
msg );
191 const
char * const prefix );
198 virtual const
char*
what() const noexcept
override {
return _msg.c_str(); }
205 virtual std::ostream&
dumpOn(std::ostream& str)
const;
219 std::ostream & dumpError( std::ostream & str )
const;
238 NullPointerException()
239 :
Exception(
"Null pointer", LogLevel::ERROR)
242 virtual ~NullPointerException()
noexcept
257 virtual ~UnsupportedException()
noexcept {}
271 virtual ~LogicException()
noexcept {}
284 OutOfMemoryException()
285 :
Exception(
"Out of memory", LogLevel::ERROR)
288 virtual ~OutOfMemoryException()
noexcept
312 const std::string &
msg =
"" )
314 , _invalidIndex( invalidIndex )
315 , _validMin( validMin )
316 , _validMax( validMax )
327 int invalidIndex() const ST_DEPRECATED {
return _invalidIndex; }
334 int validMin() const ST_DEPRECATED {
return _validMin; }
341 int validMax() const ST_DEPRECATED {
return _validMax; }
349 virtual std::ostream&
dumpOn(std::ostream& str)
const override
351 std::string prefix =
msg();
353 if ( prefix.empty() )
354 prefix =
"Index out of range";
356 return str << prefix <<
": " << _invalidIndex
357 <<
" valid: " << _validMin <<
" .. " << _validMax
377 OverflowException() :
Exception(
"overflow") {}
378 virtual ~OverflowException()
noexcept {}
391 virtual ~IOException()
noexcept {}
412 const std::string &
seen,
428 const std::string &
seen()
const {
return _seen; }
433 const std::string &
expected()
const {
return _expected; }
439 virtual std::ostream&
dumpOn(std::ostream& str)
const override
441 std::string prefix =
"Parse error";
443 if ( !
msg().empty() )
446 return str << prefix <<
msg()
447 <<
"; expected: \"" << _expected
448 <<
"\" seen: \"" << _seen <<
"\""
455 std::string _expected;
469 Aborted(
const std::string& message) :
Exception(message) {}
470 virtual ~Aborted()
noexcept {}
Helper class for UI exceptions: Store BASE_FILE, FUNCTION and LINE.
Definition Exception.h:49
const std::string & file() const
Returns the source file name where the exception occurred.
Definition Exception.h:72
const std::string & func() const
Returns the name of the function where the exception occurred.
Definition Exception.h:77
friend std::ostream & operator<<(std::ostream &str, const CodeLocation &obj)
Stream output.
std::string as_string() const
Returns the location in normalized string format.
CodeLocation()
Default constructor.
Definition Exception.h:65
CodeLocation(const std::string &file_r, const std::string &func_r, int line_r)
Constructor.
Definition Exception.h:56
int line() const
Returns the source line number where the exception occurred.
Definition Exception.h:82
Base class for storage exceptions.
Definition Exception.h:119
static void log(const Exception &exception, const CodeLocation &location, const char *const prefix)
Drop a log line on throw, catch or rethrow.
const CodeLocation & where() const
Return CodeLocation.
Definition Exception.h:142
static std::string strErrno(int errno_r)
Make a string from errno_r.
void setMsg(const std::string &msg)
Set a new message string.
Definition Exception.h:166
std::string as_string() const
Error message provided by dumpOn as string.
Exception(LogLevel log_level=LogLevel::ERROR)
Default constructor.
friend std::ostream & operator<<(std::ostream &str, const Exception &obj)
Exception stream output.
virtual std::ostream & dumpOn(std::ostream &str) const
Overload this to print a proper error message.
Exception(const std::string &msg, LogLevel log_level=LogLevel::ERROR)
Constructor taking a message.
const std::string & msg() const
Return the message string provided to the constructor.
Definition Exception.h:156
virtual const char * what() const noexcept override
Return message string.
Definition Exception.h:198
void relocate(const CodeLocation &newLocation) const
Exchange location on rethrow.
Definition Exception.h:148
virtual ~Exception() noexcept
Destructor.
Exception class for "index out of range".
Definition Exception.h:298
int valid_min() const
Return the valid minimum index.
Definition Exception.h:332
IndexOutOfRangeException(int invalidIndex, int validMin, int validMax, const std::string &msg="")
Constructor.
Definition Exception.h:309
int invalid_index() const
Return the offending index value.
Definition Exception.h:325
int valid_max() const
Return the valid maximum index.
Definition Exception.h:339
virtual std::ostream & dumpOn(std::ostream &str) const override
Write proper error message with all relevant data.
Definition Exception.h:349
virtual ~ParseException() noexcept
Destructor.
Definition Exception.h:422
ParseException(const std::string &msg, const std::string &seen, const std::string &expected)
Constructor.
Definition Exception.h:411
const std::string & expected() const
Short textual description of what the parser expected.
Definition Exception.h:433
virtual std::ostream & dumpOn(std::ostream &str) const override
Write proper error message with all relevant data.
Definition Exception.h:439
const std::string & seen() const
The offending line that caused the parse error.
Definition Exception.h:428
The storage namespace.
Definition Actiongraph.h:40
LogLevel
Enum with log levels.
Definition Logger.h:37