[ VIGRA Homepage | Class Index | Function Index | File Index | Main Page ]
|
Error Reporting | ![]() |
|---|
Exceptions and assertions provided by VIGRA
#include "vigra/error.hxx"
VIGRA defines the following exception classes:
namespace vigra { class ContractViolation : public std::exception; class PreconditionViolation : public ContractViolation; class PostconditionViolation : public ContractViolation; class InvariantViolation : public ContractViolation; }
The following associated macros throw the corresponding exception if their PREDICATE evaluates to 'false':
vigra_precondition(PREDICATE, MESSAGE);
vigra_postcondition(PREDICATE, MESSAGE);
vigra_invariant(PREDICATE, MESSAGE);
The MESSAGE is passed to the exception and can be retrieved via the overloaded member function 'exception.what()'. If the compiler flag 'NDEBUG' is not defined, the file name and line number of the error are automatically included in the message.
The following macro
vigra_fail(MESSAGE);
unconditionally throws a 'std::runtime_error' constructed from the message (along with file name and line number, if NDEBUG is not set).
Usage:
Include-File: "vigra/error.hxx"
Namespace: vigra (except for the macros, of course)
int main(int argc, char ** argv) { try { const char* input_file_name = argv[1]; // read input image vigra::ImageImportInfo info(input_file_name); // fail if input image is not grayscale vigra_precondition(info.isGrayscale(), "Input image must be grayscale"); ...// process image } catch (std::exception & e) { std::cerr << e.what() << std::endl; // print message return 1; } return 0; }
|
© Ullrich Köthe (koethe@informatik.uni-hamburg.de) |
html generated using doxygen and Python
|