00001 #ifndef vil_exception_h_
00002 #define vil_exception_h_
00003
00004
00005
00006
00007
00008 #include <vcl_string.h>
00009 #include <vcl_cstdlib.h>
00010 #include <vcl_iostream.h>
00011 #if VCL_HAS_EXCEPTIONS
00012 # include <vcl_stdexcept.h>
00013 #endif
00014 #include <vil/vil_pixel_format.h>
00015
00016
00017
00018
00019
00020 template <class T>
00021 void vil_exception_error(T exception)
00022 {
00023 #if !defined VXL_LEGACY_ERROR_REPORTING && VCL_HAS_EXCEPTIONS
00024 throw exception;
00025 #else
00026 vcl_cerr << "\nERROR: " << exception.what() << vcl_endl;
00027 vcl_abort();
00028 #endif
00029 }
00030
00031
00032
00033
00034 template <class T>
00035 void vil_exception_warning(T exception)
00036 {
00037 #if !defined VXL_LEGACY_ERROR_REPORTING && VCL_HAS_EXCEPTIONS
00038 throw exception;
00039 #else
00040 vcl_cerr << "\nWARNING: " << exception.what() << vcl_endl;
00041 #endif
00042 }
00043
00044
00045 class vil_exception_pixel_formats_incompatible
00046 #if VCL_HAS_EXCEPTIONS
00047 : public vcl_logic_error
00048 #endif
00049 {
00050 public:
00051 enum vil_pixel_format src_type, dest_type;
00052 vcl_string operation_name;
00053 vil_exception_pixel_formats_incompatible(
00054 enum vil_pixel_format src, enum vil_pixel_format dest, const vcl_string& operation) :
00055 #if VCL_HAS_EXCEPTIONS
00056 vcl_logic_error(operation + ": Pixel formats incompatible."),
00057 #endif
00058 src_type(src), dest_type(dest), operation_name(operation) {}
00059 #if VCL_HAS_EXCEPTIONS
00060 virtual ~vil_exception_pixel_formats_incompatible() throw() {}
00061 #else
00062 const char * what() const {return "Pixel formats incompatible.";}
00063 #endif
00064 };
00065
00066
00067
00068 class vil_exception_unsupported_pixel_format
00069 #if VCL_HAS_EXCEPTIONS
00070 : public vcl_logic_error
00071 #endif
00072 {
00073 public:
00074 enum vil_pixel_format src_type;
00075 vcl_string operation_name;
00076 vil_exception_unsupported_pixel_format(
00077 enum vil_pixel_format src, const vcl_string& operation) :
00078 #if VCL_HAS_EXCEPTIONS
00079 vcl_logic_error(operation + ": Unsupported pixel format."),
00080 #endif
00081 src_type(src), operation_name(operation) {}
00082 #if VCL_HAS_EXCEPTIONS
00083 virtual ~vil_exception_unsupported_pixel_format() throw() {}
00084 #else
00085 const char * what() const {return "Unsupported Pixel formats.";}
00086 #endif
00087 };
00088
00089
00090
00091
00092
00093
00094
00095 class vil_exception_out_of_bounds
00096 #if VCL_HAS_EXCEPTIONS
00097 : public vcl_logic_error
00098 #endif
00099 {
00100 public:
00101 vcl_string operation_name;
00102 vil_exception_out_of_bounds(
00103 const vcl_string& operation) :
00104 #if VCL_HAS_EXCEPTIONS
00105 vcl_logic_error(operation + ": Pixel access out-of-bounds."),
00106 #endif
00107 operation_name(operation) {}
00108 #if VCL_HAS_EXCEPTIONS
00109 virtual ~vil_exception_out_of_bounds() throw() {}
00110 #else
00111 const char * what() const {return "Pixel access out-of-bounds.";}
00112 #endif
00113 };
00114
00115
00116
00117
00118
00119
00120
00121 class vil_exception_unsupported_operation
00122 #if VCL_HAS_EXCEPTIONS
00123 : public vcl_logic_error
00124 #endif
00125 {
00126 public:
00127 vcl_string operation_name;
00128 vil_exception_unsupported_operation(
00129 const vcl_string& operation) :
00130 #if VCL_HAS_EXCEPTIONS
00131 vcl_logic_error(operation + ": Unsupported operation."),
00132 #endif
00133 operation_name(operation) {}
00134 #if VCL_HAS_EXCEPTIONS
00135 virtual ~vil_exception_unsupported_operation() throw() {}
00136 #else
00137 const char * what() const {return "Unsupported operation.";}
00138 #endif
00139 };
00140
00141
00142
00143
00144
00145
00146
00147 class vil_exception_image_io
00148 #if VCL_HAS_EXCEPTIONS
00149 : public vcl_runtime_error
00150 #endif
00151 {
00152 public:
00153 #if !VCL_HAS_EXCEPTIONS
00154 vcl_string full_what;
00155 #endif
00156 vcl_string function_name, file_type, filename, details;
00157 vil_exception_image_io(const vcl_string& function,
00158 const vcl_string& type,
00159 const vcl_string& file_name,
00160 const vcl_string& description = "") :
00161 #if VCL_HAS_EXCEPTIONS
00162 vcl_runtime_error
00163 #else
00164 full_what
00165 #endif
00166 ("Unrecoverable failure in " + function + " while loading "
00167 + file_name + " using " + type + " loader. Error description: " + description),
00168 function_name(function), file_type(type), filename(file_name), details(description) {}
00169 #if VCL_HAS_EXCEPTIONS
00170 virtual ~vil_exception_image_io() throw() {}
00171 #else
00172 const char * what() const { return full_what.c_str(); }
00173 #endif
00174 };
00175
00176
00177
00178
00179
00180 class vil_exception_corrupt_image_file
00181 #if VCL_HAS_EXCEPTIONS
00182 : public vil_exception_image_io
00183 #endif
00184 {
00185 public:
00186 vil_exception_corrupt_image_file(const vcl_string& function,
00187 const vcl_string& type,
00188 const vcl_string& file_name,
00189 const vcl_string& description = "") :
00190 #if VCL_HAS_EXCEPTIONS
00191 vil_exception_image_io(function, type, file_name, description)
00192 #endif
00193 {}
00194 #if VCL_HAS_EXCEPTIONS
00195 virtual ~vil_exception_corrupt_image_file() throw() {}
00196 #else
00197 const char * what() const {return "Image file is corrupt.";}
00198 #endif
00199 };
00200
00201
00202
00203
00204 class vil_exception_invalid_version
00205 #if VCL_HAS_EXCEPTIONS
00206 : public vil_exception_image_io
00207 #endif
00208 {
00209 public:
00210 vil_exception_invalid_version(const vcl_string& function,
00211 const vcl_string& type,
00212 const vcl_string& file_name,
00213 const vcl_string& description = "")
00214 #if VCL_HAS_EXCEPTIONS
00215 : vil_exception_image_io(function, type, file_name, description)
00216 #endif
00217 {}
00218 #if VCL_HAS_EXCEPTIONS
00219 virtual ~vil_exception_invalid_version() throw() {}
00220 #else
00221 const char * what() const {return "Unknown version number detected in file";}
00222 #endif
00223 };
00224
00225 #endif // vil_exception_h_