37 #ifndef VIGRA_ERROR_HXX
38 #define VIGRA_ERROR_HXX
125 class ContractViolation :
public StdException
131 ContractViolation(
char const * prefix,
char const * message,
132 char const * file,
int line)
134 (*this) <<
"\n" << prefix <<
"\n" << message <<
"\n("
135 << file <<
":" << line <<
")\n";
138 ContractViolation(
char const * prefix,
char const * message)
140 (*this) <<
"\n" << prefix <<
"\n" << message <<
"\n";
143 ~ContractViolation() throw()
147 ContractViolation &
operator<<(T
const & data)
149 std::ostringstream what;
155 virtual const char * what()
const throw()
159 return what_.c_str();
163 return "vigra::ContractViolation: error message was lost, sorry.";
171 class PreconditionViolation :
public ContractViolation
174 PreconditionViolation(
char const * message,
const char * file,
int line)
175 : ContractViolation(
"Precondition violation!", message, file, line)
178 PreconditionViolation(
char const * message)
179 : ContractViolation(
"Precondition violation!", message)
183 class PostconditionViolation :
public ContractViolation
186 PostconditionViolation(
char const * message,
const char * file,
int line)
187 : ContractViolation(
"Postcondition violation!", message, file, line)
190 PostconditionViolation(
char const * message)
191 : ContractViolation(
"Postcondition violation!", message)
195 class InvariantViolation :
public ContractViolation
198 InvariantViolation(
char const * message,
const char * file,
int line)
199 : ContractViolation(
"Invariant violation!", message, file, line)
202 InvariantViolation(
char const * message)
203 : ContractViolation(
"Invariant violation!", message)
212 void throw_invariant_error(
bool predicate,
char const * message,
char const * file,
int line)
215 throw vigra::InvariantViolation(message, file, line);
219 void throw_invariant_error(
bool predicate, std::string message,
char const * file,
int line)
222 throw vigra::InvariantViolation(message.c_str(), file, line);
226 void throw_precondition_error(
bool predicate,
char const * message,
char const * file,
int line)
229 throw vigra::PreconditionViolation(message, file, line);
233 void throw_precondition_error(
bool predicate, std::string message,
char const * file,
int line)
236 throw vigra::PreconditionViolation(message.c_str(), file, line);
240 void throw_postcondition_error(
bool predicate,
char const * message,
char const * file,
int line)
243 throw vigra::PostconditionViolation(message, file, line);
247 void throw_postcondition_error(
bool predicate, std::string message,
char const * file,
int line)
250 throw vigra::PostconditionViolation(message.c_str(), file, line);
254 void throw_runtime_error(
char const * message,
char const * file,
int line)
256 std::ostringstream what;
257 what <<
"\n" << message <<
"\n(" << file <<
":" << line <<
")\n";
258 throw std::runtime_error(what.str());
262 void throw_runtime_error(std::string message,
char const * file,
int line)
264 std::ostringstream what;
265 what <<
"\n" << message <<
"\n(" << file <<
":" << line <<
")\n";
266 throw std::runtime_error(what.str());
269 #define vigra_precondition(PREDICATE, MESSAGE) vigra::throw_precondition_error((PREDICATE), MESSAGE, __FILE__, __LINE__)
271 #define vigra_assert(PREDICATE, MESSAGE) vigra_precondition(PREDICATE, MESSAGE)
273 #define vigra_postcondition(PREDICATE, MESSAGE) vigra::throw_postcondition_error((PREDICATE), MESSAGE, __FILE__, __LINE__)
275 #define vigra_invariant(PREDICATE, MESSAGE) vigra::throw_invariant_error((PREDICATE), MESSAGE, __FILE__, __LINE__)
277 #define vigra_fail(MESSAGE) vigra::throw_runtime_error(MESSAGE, __FILE__, __LINE__)
282 void throw_invariant_error(
bool predicate,
char const * message)
285 throw vigra::InvariantViolation(message);
289 void throw_precondition_error(
bool predicate,
char const * message)
292 throw vigra::PreconditionViolation(message);
296 void throw_postcondition_error(
bool predicate,
char const * message)
299 throw vigra::PostconditionViolation(message);
303 void throw_invariant_error(
bool predicate, std::string message)
306 throw vigra::InvariantViolation(message.c_str());
310 void throw_precondition_error(
bool predicate, std::string message)
313 throw vigra::PreconditionViolation(message.c_str());
317 void throw_postcondition_error(
bool predicate, std::string message)
320 throw vigra::PostconditionViolation(message.c_str());
323 #define vigra_precondition(PREDICATE, MESSAGE) vigra::throw_precondition_error((PREDICATE), MESSAGE)
325 #define vigra_assert(PREDICATE, MESSAGE)
327 #define vigra_postcondition(PREDICATE, MESSAGE) vigra::throw_postcondition_error((PREDICATE), MESSAGE)
329 #define vigra_invariant(PREDICATE, MESSAGE) vigra::throw_invariant_error((PREDICATE), MESSAGE)
331 #define vigra_fail(MESSAGE) throw std::runtime_error(MESSAGE)
337 #endif // VIGRA_ERROR_HXX
Definition: accessor.hxx:43
ostream & operator<<(ostream &s, const vigra::MultiArrayView< 2, T, C > &m)
Definition: matrix.hxx:2322