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; }
166 void setMsg(
const std::string& msg) { _msg = msg; }
173 std::string asString() const ST_DEPRECATED;
178 static std::
string strErrno(
int errno_r );
183 static std::
string strErrno(
int errno_r, const std::
string & msg );
189 static
void log( const
Exception & exception,
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;
227 std::ostream &
operator<<( std::ostream & str,
const Exception & obj );
239 :
Exception(
"Null pointer", LogLevel::ERROR)
285 :
Exception(
"Out of memory", LogLevel::ERROR)
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
412 const std::string & seen,
413 const std::string & expected ):
416 _expected( expected )
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;
CodeLocation()
Default constructor.
Definition: Exception.h:65
virtual std::ostream & dumpOn(std::ostream &str) const override
Write proper error message with all relevant data.
Definition: Exception.h:439
Exception class for "index out of range".
Definition: Exception.h:297
Exception class for "overflow".
Definition: Exception.h:373
const std::string & msg() const
Return the message string provided to the constructor.
Definition: Exception.h:156
int invalid_index() const
Return the offending index value.
Definition: Exception.h:325
virtual std::ostream & dumpOn(std::ostream &str) const override
Write proper error message with all relevant data.
Definition: Exception.h:349
std::string as_string() const
Returns the location in normalized string format.
const std::string & seen() const
The offending line that caused the parse error.
Definition: Exception.h:428
Exception class for "out of memory".
Definition: Exception.h:280
Exception class for faulty logic within the program.
Definition: Exception.h:266
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:48
ParseException(const std::string &msg, const std::string &seen, const std::string &expected)
Constructor.
Definition: Exception.h:411
Exception class for parse errors, e.g.
Definition: Exception.h:400
int valid_max() const
Return the valid maximum index.
Definition: Exception.h:339
Definition: Exception.h:465
const std::string & func() const
Returns the name of the function where the exception occurred.
Definition: Exception.h:77
const CodeLocation & where() const
Return CodeLocation.
Definition: Exception.h:142
void setMsg(const std::string &msg)
Set a new message string.
Definition: Exception.h:166
Exception class for generic null pointer exceptions.
Definition: Exception.h:234
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
LogLevel
Enum with log levels.
Definition: Logger.h:37
Base class for storage exceptions.
Definition: Exception.h:118
int line() const
Returns the source line number where the exception occurred.
Definition: Exception.h:82
The storage namespace.
Definition: Actiongraph.h:39
void relocate(const CodeLocation &newLocation) const
Exchange location on rethrow.
Definition: Exception.h:148
const std::string & file() const
Returns the source file name where the exception occurred.
Definition: Exception.h:72
virtual ~ParseException() noexcept
Destructor.
Definition: Exception.h:422
Exception class for unsupported features and operations.
Definition: Exception.h:252
Exception class for IO errors.
Definition: Exception.h:386
const std::string & expected() const
Short textual description of what the parser expected.
Definition: Exception.h:433
CodeLocation(const std::string &file_r, const std::string &func_r, int line_r)
Constructor.
Definition: Exception.h:56