summaryrefslogtreecommitdiff
path: root/error.h
blob: 51d152cdee1e6d5a211c2531a06017d5aa233887 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#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.c_str();
  }
};

class compute_error : public error
{
 public:
  compute_error(const std::string& reason) throw() : error(reason) {}
  virtual ~compute_error() throw() {}
};

class expr_error : public error
{
 public:
  expr_error(const std::string& reason) throw() : error(reason) {}
  virtual ~expr_error() throw() {}
};

class format_error : public error
{
 public:
  format_error(const std::string& reason) throw() : error(reason) {}
  virtual ~format_error() throw() {}
};

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()
    : error(reason), line(_line), file(_file) {}
  virtual ~parse_error() throw() {}

  virtual const char* what() const throw() {
    static std::ostringstream msg;
    msg << file << ", line " << line << ": " << error::what();
    return msg.str().c_str();
  }
};

} // namespace ledger

#endif // _CONSTRAINT_H