ivl 679
|
00001 /* This file is part of the ivl C++ library <http://image.ntua.gr/ivl>. 00002 A C++ template library extending syntax towards mathematical notation. 00003 00004 Copyright (C) 2012 Yannis Avrithis <iavr@image.ntua.gr> 00005 Copyright (C) 2012 Kimon Kontosis <kimonas@image.ntua.gr> 00006 00007 ivl is free software; you can redistribute it and/or modify 00008 it under the terms of the GNU Lesser General Public License 00009 version 3 as published by the Free Software Foundation. 00010 00011 Alternatively, you can redistribute it and/or modify it under the terms 00012 of the GNU General Public License version 2 as published by the Free 00013 Software Foundation. 00014 00015 ivl is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00018 See the GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 and a copy of the GNU Lesser General Public License along 00022 with ivl. If not, see <http://www.gnu.org/licenses/>. */ 00023 00029 #ifndef IVL_EXCEPTION_HPP 00030 #define IVL_EXCEPTION_HPP 00031 00032 #include "details/core/platform_specific/msc_warnings.hpp" 00033 00034 #include <exception> 00035 #include <cassert> 00036 00037 namespace ivl { 00038 00039 #ifdef _DEBUG 00040 00041 #ifndef THROW_EXCEPTION 00042 #define CHECK(expr, excep) \ 00043 assert(expr); 00044 #else 00045 #define CHECK(expr, excep) \ 00046 assert(expr); \ 00047 if(expr == false) \ 00048 throw(excep); 00049 #endif 00050 #define CHECK_RELEASE(expr, exec) \ 00051 if(expr == false) \ 00052 throw(excep); 00053 #define CHECK_LINA(expr, exec) \ 00054 if(expr == false) \ 00055 throw(excep); 00056 #define CHECK_OPENCV(expr, exec) \ 00057 if(expr == false) \ 00058 throw(excep); 00059 00060 #else 00061 00062 #define CHECK(expr, excep) ; 00063 00064 #endif 00065 00066 //TODO: implement the throw decision mechanism. 00067 /* The rules are: 00068 00069 We have 1 switch for each expression type, that enables/disables it 00070 in THROW_RELEASE mode. 00071 We have 1 switch for each extra category, LINA, OPENCV. 00072 We have 1 switch for simple CHECK that enables/disable it. That switch 00073 is on by default in the DEBUG mode. 00074 00075 */ 00076 // These switches should change to "throw()" when the corresponding switch is set to off. 00077 #define __dbg_throw(A) throw(A) 00078 #define __rel_throw(A) throw(A) 00079 #define __lina_throw(A) throw(A) 00080 #define __opencv_throw(A) throw(A) 00081 00082 00083 00084 class exception : public std::exception 00085 { 00086 public : 00087 virtual const char* what() const throw() 00088 { 00089 return "An IVL exception occured!"; 00090 } 00091 }; 00092 00093 class einvalid : public exception 00094 { 00095 public : 00096 virtual const char* what() const throw() 00097 { 00098 // A pointer has NULL. 00099 return "Pointer value is not valid."; 00100 } 00101 00102 }; 00103 00104 // ?? What if array is empty but non-empty is needed? 00105 // ?? What is array is <3 but >=3 is needed? 00106 // erange? no. eshape? it is not the exact exception 00107 // i probably need an esize 00108 //TODO: use esize. 00109 00110 class erange : public exception 00111 { 00112 public : 00113 virtual const char* what() const throw() 00114 { 00115 // We are trying to access out of the array bounds. 00116 return "Value is out of range."; 00117 } 00118 00119 }; 00120 00121 class eshape : public exception 00122 { 00123 public : 00124 virtual const char* what() const throw() 00125 { 00126 return "The shape of these arrays is not compatible for this kind of operation."; 00127 } 00128 00129 }; 00130 00131 class etype : public exception 00132 { 00133 public : 00134 virtual const char* what() const throw() 00135 { 00136 // When communicating with another library that has abstract types, 00137 // it is possible to have this kind of exceptions 00138 return "The data type of these arrays is not compatible for this kind of operation."; 00139 } 00140 00141 }; 00142 00143 class edims : public exception 00144 { 00145 public : 00146 virtual const char* what() const throw() 00147 { 00148 return "Incorrect number of dimensions in array."; 00149 } 00150 00151 }; 00152 00153 class ecomp : public exception 00154 { 00155 public : 00156 virtual const char* what() const throw() 00157 { 00158 // Generic exception which means that an expression cannot be computed, 00159 // probably because of the argument values. 00160 return "Illegal computation"; 00161 } 00162 }; 00163 00164 class esystem : public exception 00165 { 00166 public: 00167 virtual const char* what() const throw() 00168 { 00169 // Any kind of error that doesn't depend on the CPU, but on any other 00170 // kind of i/o, including memory allocation or other system calls failure. 00171 return "System error"; 00172 } 00173 }; 00174 00175 } /* namespace ivl */ 00176 00177 #endif // IVL_EXCEPTION_HPP