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)
208 void throw_invariant_error(
bool predicate,
char const * message,
char const * file,
int line)
211 throw vigra::InvariantViolation(message, file, line);
215 void throw_invariant_error(
bool predicate, std::string message,
char const * file,
int line)
218 throw vigra::InvariantViolation(message.c_str(), file, line);
222 void throw_precondition_error(
bool predicate,
char const * message,
char const * file,
int line)
225 throw vigra::PreconditionViolation(message, file, line);
229 void throw_precondition_error(
bool predicate, std::string message,
char const * file,
int line)
232 throw vigra::PreconditionViolation(message.c_str(), file, line);
236 void throw_postcondition_error(
bool predicate,
char const * message,
char const * file,
int line)
239 throw vigra::PostconditionViolation(message, file, line);
243 void throw_postcondition_error(
bool predicate, std::string message,
char const * file,
int line)
246 throw vigra::PostconditionViolation(message.c_str(), file, line);
250 void throw_runtime_error(
char const * message,
char const * file,
int line)
252 std::ostringstream what;
253 what <<
"\n" << message <<
"\n(" << file <<
":" << line <<
")\n";
254 throw std::runtime_error(what.str());
258 void throw_runtime_error(std::string message,
char const * file,
int line)
260 std::ostringstream what;
261 what <<
"\n" << message <<
"\n(" << file <<
":" << line <<
")\n";
262 throw std::runtime_error(what.str());
265 #define vigra_precondition(PREDICATE, MESSAGE) vigra::throw_precondition_error((PREDICATE), MESSAGE, __FILE__, __LINE__)
269 #define vigra_assert(PREDICATE, MESSAGE)
271 #define vigra_assert(PREDICATE, MESSAGE) vigra_precondition(PREDICATE, MESSAGE)
274 #define vigra_postcondition(PREDICATE, MESSAGE) vigra::throw_postcondition_error((PREDICATE), MESSAGE, __FILE__, __LINE__)
276 #define vigra_invariant(PREDICATE, MESSAGE) vigra::throw_invariant_error((PREDICATE), MESSAGE, __FILE__, __LINE__)
278 #define vigra_fail(MESSAGE) vigra::throw_runtime_error(MESSAGE, __FILE__, __LINE__)
282 #endif // VIGRA_ERROR_HXX