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; }
143 { _where = newLocation; }
150 const std::string&
msg()
const {
return _msg; }
155 LogLevel log_level()
const {
return _log_level; }
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;
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;
Definition: Exception.h:443
Helper class for UI exceptions: Store BASE_FILE, FUNCTION and LINE.
Definition: Exception.h:48
const std::string & file() const
Returns the source file name where the exception occured.
Definition: Exception.h:70
const std::string & func() const
Returns the name of the function where the exception occured.
Definition: Exception.h:75
friend std::ostream & operator<<(std::ostream &str, const CodeLocation &obj)
Stream output.
std::string asString() const
Returns the location in normalized string format.
CodeLocation()
Default constructor.
Definition: Exception.h:63
CodeLocation(const std::string &file_r, const std::string &func_r, int line_r)
Constructor.
Definition: Exception.h:54
int line() const
Returns the source line number where the exception occured.
Definition: Exception.h:80
Base class for storage exceptions.
Definition: Exception.h:114
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:136
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:160
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.
std::string asString() const
Error message provided by dumpOn as string.
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:150
static std::string strErrno(int errno_r, const std::string &msg)
Make a string from errno_r and msg_r.
virtual const char * what() const noexcept override
Return message string.
Definition: Exception.h:190
void relocate(const CodeLocation &newLocation) const
Exchange location on rethrow.
Definition: Exception.h:142
virtual ~Exception() noexcept
Destructor.
Exception class for IO errors.
Definition: Exception.h:365
Exception class for "index out of range".
Definition: Exception.h:284
int validMax() const
Return the valid maximum index.
Definition: Exception.h:320
IndexOutOfRangeException(int invalidIndex, int validMin, int validMax, const std::string &msg="")
Constructor.
Definition: Exception.h:294
virtual std::ostream & dumpOn(std::ostream &str) const override
Write proper error message with all relevant data.
Definition: Exception.h:328
int validMin() const
Return the valid minimum index.
Definition: Exception.h:315
int invalidIndex() const
Return the offending index value.
Definition: Exception.h:310
Exception class for faulty logic within the program.
Definition: Exception.h:256
Exception class for generic null pointer exceptions.
Definition: Exception.h:228
Exception class for "out of memory".
Definition: Exception.h:268
Exception class for "overflow".
Definition: Exception.h:352
Exception class for parse errors, e.g.
Definition: Exception.h:379
virtual ~ParseException() noexcept
Destructor.
Definition: Exception.h:400
ParseException(const std::string &msg, const std::string &seen, const std::string &expected)
Constructor.
Definition: Exception.h:389
const std::string & expected() const
Short textual description of what the parser expected.
Definition: Exception.h:411
virtual std::ostream & dumpOn(std::ostream &str) const override
Write proper error message with all relevant data.
Definition: Exception.h:417
const std::string & seen() const
The offending line that caused the parse error.
Definition: Exception.h:406
Exception class for unsupported features and operations.
Definition: Exception.h:244
The storage namespace.
Definition: Actiongraph.h:39
std::ostream & operator<<(std::ostream &str, const CodeLocation &obj)
CodeLocation stream output.
LogLevel
Enum with log levels.
Definition: Logger.h:37