diff options
author | John Wiegley <johnw@newartisans.com> | 2004-07-29 01:49:31 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2004-07-29 01:49:31 -0400 |
commit | e2432a4000fc48e2c79aadc2a3a14c37b723174e (patch) | |
tree | a2d3bee68d8ff20d3d28daee926b37473cca41a9 | |
parent | 0fdf03087304828a66bfd723eb65f3153482eea1 (diff) | |
download | ledger-e2432a4000fc48e2c79aadc2a3a14c37b723174e.tar.gz ledger-e2432a4000fc48e2c79aadc2a3a14c37b723174e.tar.bz2 ledger-e2432a4000fc48e2c79aadc2a3a14c37b723174e.zip |
added error.h
-rw-r--r-- | error.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/error.h b/error.h new file mode 100644 index 00000000..7e069218 --- /dev/null +++ b/error.h @@ -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 |