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
00122 class vil_exception_unsupported_operation
00123 #if VCL_HAS_EXCEPTIONS
00124 : public vcl_logic_error
00125 #endif
00126 {
00127 public:
00128 vcl_string operation_name;
00129 vil_exception_unsupported_operation(
00130 const vcl_string& operation) :
00131 #if VCL_HAS_EXCEPTIONS
00132 vcl_logic_error(operation + ": Unsupported operation."),
00133 #endif
00134 operation_name(operation) {}
00135 #if VCL_HAS_EXCEPTIONS
00136 virtual ~vil_exception_unsupported_operation() throw() {}
00137 #else
00138 const char * what() const {return "Unsupported operation.";}
00139 #endif
00140 };
00141
00142
00143
00144
00145
00146
00147
00148 class vil_exception_image_io
00149 #if VCL_HAS_EXCEPTIONS
00150 : public vcl_runtime_error
00151 #endif
00152 {
00153 public:
00154 #if !VCL_HAS_EXCEPTIONS
00155 vcl_string full_what;
00156 #endif
00157 vcl_string function_name, file_type, filename;
00158 vil_exception_image_io(const vcl_string& function,
00159 const vcl_string& type,
00160 const vcl_string& name) :
00161 #if VCL_HAS_EXCEPTIONS
00162 vcl_runtime_error
00163 #else
00164 full_what
00165 #endif
00166 ("Unrecoverable failure in " + function + " while loading "
00167 + name + " using " + type + " loader."),
00168 function_name(function), file_type(type), filename(name) {}
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 #endif // vil_exception_h_
00181