Scribus
Open source desktop publishing at your fingertips
exception.h
1 #ifndef LIB2GEOM_EXCEPTION_HEADER
2 #define LIB2GEOM_EXCEPTION_HEADER
3 
33 #include <exception>
34 #include <sstream>
35 #include <string>
36 
37 namespace Geom {
38 
39 // Base exception class, all 2geom exceptions should be derrived from this one.
40 class Exception : public std::exception {
41 public:
42  Exception(const char * message, const char *file, const int line) {
43  std::ostringstream os;
44  os << "lib2geom exception: " << message << " (" << file << ":" << line << ")";
45  msgstr = os.str();
46  }
47 
48  virtual ~Exception() throw() {} // necessary to destroy the string object!!!
49 
50  virtual const char* what() const throw () {
51  return msgstr.c_str();
52  }
53 protected:
54  std::string msgstr;
55 };
56 #define throwException(message) throw(Geom::Exception(message, __FILE__, __LINE__))
57 
58 //-----------------------------------------------------------------------
59 // Two main exception classes: LogicalError and RangeError.
60 // Logical errors are 2geom faults/bugs, RangeErrors are 'user' faults.
61 // This way, the 'user' can distinguish between groups of exceptions
62 // ('user' is the coder that uses lib2geom)
63 class LogicalError : public Exception {
64 public:
65  LogicalError(const char * message, const char *file, const int line)
66  : Exception(message, file, line) {}
67 };
68 #define throwLogicalError(message) throw(LogicalError(message, __FILE__, __LINE__))
69 
70 class RangeError : public Exception {
71 public:
72  RangeError(const char * message, const char *file, const int line)
73  : Exception(message, file, line) {}
74 };
75 #define throwRangeError(message) throw(RangeError(message, __FILE__, __LINE__))
76 
77 //-----------------------------------------------------------------------
78 // Special case exceptions. Best used with the defines :)
79 
80 class NotImplemented : public LogicalError {
81 public:
82  NotImplemented(const char *file, const int line)
83  : LogicalError("Method not implemented", file, line) {}
84 };
85 #define throwNotImplemented(i) throw(NotImplemented(__FILE__, __LINE__))
86 
88 public:
89  InvariantsViolation(const char *file, const int line)
90  : LogicalError("Invariants violation", file, line) {}
91 };
92 #define throwInvariantsViolation(i) throw(InvariantsViolation(__FILE__, __LINE__))
93 #define assert_invariants(e) ((e) ? (void)0 : throwInvariantsViolation(0))
94 
95 class NotInvertible : public RangeError {
96 public:
97  NotInvertible(const char *file, const int line)
98  : RangeError("Function does not have a unique inverse", file, line) {}
99 };
100 #define throwNotInvertible(i) throw(NotInvertible(__FILE__, __LINE__))
101 
102 class ContinuityError : public RangeError {
103 public:
104  ContinuityError(const char *file, const int line)
105  : RangeError("Non-contiguous path", file, line) {}
106 };
107 #define throwContinuityError(i) throw(ContinuityError(__FILE__, __LINE__))
108 
109 struct SVGPathParseError : public std::exception {
110  char const *what() const throw() { return "parse error"; }
111 };
112 
113 
114 } // namespace Geom
115 
116 #endif
Definition: exception.h:109
Definition: angle.h:38
Definition: exception.h:87
Definition: exception.h:80
Definition: exception.h:63
Definition: exception.h:102
Definition: exception.h:40
Definition: exception.h:70
Definition: exception.h:95