88 * |
95 * |
89 * Base class for exceptions used in LEMON. |
96 * Base class for exceptions used in LEMON. |
90 */ |
97 */ |
91 class Exception : public std::exception, public ErrorMessage { |
98 class Exception : public std::exception, public ErrorMessage { |
92 public: |
99 public: |
|
100 ///\e |
93 Exception() throw() {} |
101 Exception() throw() {} |
|
102 ///\e |
94 explicit Exception(const std::string &s) throw() |
103 explicit Exception(const std::string &s) throw() |
95 : ErrorMessage(s) {} |
104 : ErrorMessage(s) {} |
|
105 ///\e |
96 virtual ~Exception() throw() {} |
106 virtual ~Exception() throw() {} |
97 |
107 |
|
108 ///\e |
98 virtual const char* what() const throw() { |
109 virtual const char* what() const throw() { |
99 const char *mes = message(); |
110 const char *mes = message(); |
100 if( mes ) return mes; |
111 if( mes ) return mes; |
101 return "lemon::Exception"; |
112 return "lemon::Exception"; |
102 } |
113 } |
103 }; |
114 }; |
104 |
115 |
105 |
116 ///\e |
106 class LogicError : public Exception { |
117 class LogicError : public Exception { |
|
118 ///\e |
107 explicit LogicError(const std::string &s) |
119 explicit LogicError(const std::string &s) |
108 : Exception(s) {} |
120 : Exception(s) {} |
109 }; |
121 }; |
110 |
122 |
|
123 ///\e |
111 class RuntimeError : public Exception { |
124 class RuntimeError : public Exception { |
|
125 ///\e |
112 explicit RuntimeError(const std::string &s) |
126 explicit RuntimeError(const std::string &s) |
113 : Exception(s) {} |
127 : Exception(s) {} |
114 }; |
128 }; |
115 |
129 |
|
130 ///\e |
116 class RangeError : public RuntimeError { |
131 class RangeError : public RuntimeError { |
|
132 ///\e |
117 explicit RangeError(const std::string &s) |
133 explicit RangeError(const std::string &s) |
118 : RuntimeError(s) {} |
134 : RuntimeError(s) {} |
119 }; |
135 }; |
120 |
136 |
|
137 ///\e |
121 class IOError : public RuntimeError { |
138 class IOError : public RuntimeError { |
|
139 ///\e |
122 explicit IOError(const std::string &s) |
140 explicit IOError(const std::string &s) |
123 : RuntimeError(s) {} |
141 : RuntimeError(s) {} |
124 }; |
142 }; |
125 |
143 |
|
144 ///\e |
126 class DataFormatError : public IOError { |
145 class DataFormatError : public IOError { |
|
146 ///\e |
127 explicit DataFormatError(const std::string &message) |
147 explicit DataFormatError(const std::string &message) |
128 : IOError(message) : line(0) {} |
148 : IOError(message) : line(0) {} |
|
149 ///\e |
129 DataFormatError(const std::string &file_name, int line_num, |
150 DataFormatError(const std::string &file_name, int line_num, |
130 sconst std::string &message) |
151 const std::string &message) |
131 : IOError(message), line(line_num) { set_file(file_name); } |
152 : IOError(message), line(line_num) { set_file(file_name); } |
132 |
153 |
|
154 ///\e |
133 void set_line(int line_num) { line=line_num; } |
155 void set_line(int line_num) { line=line_num; } |
|
156 ///\e |
134 void set_file(const std::string &file_name) { |
157 void set_file(const std::string &file_name) { |
135 try { |
158 try { |
136 file.reset(new std::string); |
159 file.reset(new std::string); |
137 *file = file_name; |
160 *file = file_name; |
138 } |
161 } |
139 catch(...) { |
162 catch(...) { |
140 file.reset(); |
163 file.reset(); |
141 } |
164 } |
142 } |
165 } |
143 |
166 |
|
167 ///\e |
144 virtual const char* what() const { |
168 virtual const char* what() const { |
145 const char *mes = 0; |
169 const char *mes = 0; |
146 try { |
170 try { |
147 std::ostringstream ostr; |
171 std::ostringstream ostr; |
148 ostr << IOError::what(); |
172 ostr << IOError::what(); |