added error.h
This commit is contained in:
parent
0fdf030873
commit
e2432a4000
1 changed files with 40 additions and 0 deletions
40
error.h
Normal file
40
error.h
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
#ifndef _ERROR_H
|
||||||
|
#define _ERROR_H
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace ledger {
|
||||||
|
|
||||||
|
class error : public std::exception
|
||||||
|
{
|
||||||
|
std::string reason;
|
||||||
|
public:
|
||||||
|
error(const std::string& _reason) throw() : reason(_reason) {}
|
||||||
|
virtual ~error() throw() {}
|
||||||
|
|
||||||
|
virtual const char* what() const throw() {
|
||||||
|
return reason;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class parse_error : public error
|
||||||
|
{
|
||||||
|
unsigned int line;
|
||||||
|
std::string file;
|
||||||
|
public:
|
||||||
|
parse_error(const std::string& _file, const unsigned int _line,
|
||||||
|
const std::string& reason) throw()
|
||||||
|
: line(_line), file(_file), error(reason) {}
|
||||||
|
virtual ~parse_error() throw() {}
|
||||||
|
|
||||||
|
virtual const char* what() const throw() {
|
||||||
|
static std::ostringstream msg;
|
||||||
|
msg << "Error: " << file << ", line " << line << ": " << error::what();
|
||||||
|
return msg.str().c_str();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace ledger
|
||||||
|
|
||||||
|
#endif // _CONSTRAINT_H
|
||||||
Loading…
Add table
Reference in a new issue