00001 // Software License for MTL 00002 // 00003 // Copyright (c) 2007 The Trustees of Indiana University. 00004 // 2008 Dresden University of Technology and the Trustees of Indiana University. 00005 // All rights reserved. 00006 // Authors: Peter Gottschling and Andrew Lumsdaine 00007 // 00008 // This file is part of the Matrix Template Library 00009 // 00010 // See also license.mtl.txt in the distribution. 00011 00012 #ifndef MTL_MTL_EXCEPTION_INCLUDE 00013 #define MTL_MTL_EXCEPTION_INCLUDE 00014 00015 #include <cassert> 00016 #include <stdexcept> 00017 00018 namespace mtl { 00019 00020 // If MTL_ASSERT_FOR_THROW is defined all throws become assert 00021 // MTL_DEBUG_THROW_IF completely disappears if NDEBUG is defined 00022 #ifndef NDEBUG 00023 # ifdef MTL_ASSERT_FOR_THROW 00024 # define MTL_DEBUG_THROW_IF(Test, Exception) \ 00025 { assert(!(Test)); } 00026 # else 00027 # define MTL_DEBUG_THROW_IF(Test, Exception) \ 00028 { if (Test) throw Exception; } 00029 # endif 00030 #else 00031 # define MTL_DEBUG_THROW_IF(Test,Exception) 00032 #endif 00033 00034 00035 #ifdef MTL_ASSERT_FOR_THROW 00036 # define MTL_THROW_IF(Test, Exception) \ 00037 { \ 00038 assert(!(Test)); \ 00039 } 00040 #else 00041 # define MTL_THROW_IF(Test, Exception) \ 00042 { \ 00043 if (Test) throw Exception; \ 00044 } 00045 #endif 00046 00047 00048 #ifdef MTL_ASSERT_FOR_THROW 00049 # define MTL_THROW(Exception) \ 00050 { \ 00051 assert(0); \ 00052 } 00053 #else 00054 # define MTL_THROW(Exception) \ 00055 { \ 00056 throw Exception; \ 00057 } 00058 #endif 00059 00060 00061 #if 0 00062 standard errors: 00063 00064 exception 00065 logic_error 00066 domain_error 00067 invalid_argument 00068 length_error 00069 out_of_range 00070 runtime_error 00071 range_error 00072 overflow_error 00073 underflow_error 00074 bad_alloc 00075 bad_cast 00076 bad_exception 00077 bad_typeid 00078 00079 #endif 00080 00082 struct index_out_of_range : public std::out_of_range 00083 { 00085 explicit index_out_of_range(const char *s= "Index out of range") : std::out_of_range(s) {} 00086 }; 00087 00089 struct range_error : public std::range_error 00090 { 00092 explicit range_error(const char *s= "Invalid range") : std::range_error(s) {} 00093 }; 00094 00096 struct domain_error : public std::domain_error 00097 { 00099 explicit domain_error(const char *s= "MTL4 domain error.") : std::domain_error(s) {} 00100 }; 00101 00103 struct incompatible_size : public domain_error 00104 { 00106 explicit incompatible_size(const char *s= "Arguments have incompatible size.") 00107 : domain_error(s) {} 00108 }; 00109 00111 struct change_static_size : public domain_error 00112 { 00114 explicit change_static_size(const char *s= "You try to change a fixed size (to another value).") 00115 : domain_error(s) {} 00116 }; 00117 00119 struct argument_result_conflict : public domain_error 00120 { 00122 explicit argument_result_conflict(const char *s= "Used same object illegally as argument and result.") 00123 : domain_error(s) {} 00124 }; 00125 00127 struct incompatible_shape : public domain_error 00128 { 00130 explicit incompatible_shape(const char *s= "Arguments have incompatible shape.") 00131 : domain_error(s) {} 00132 }; 00133 00135 struct matrix_not_square : public domain_error 00136 { 00138 explicit matrix_not_square(const char *s= "Matrix must be square for this operation.") 00139 : domain_error(s) {} 00140 }; 00141 00143 struct matrix_too_small : public domain_error 00144 { 00146 explicit matrix_too_small(const char *s= "Matrix is too small for certain algorithms.") 00147 : domain_error(s) {} 00148 }; 00149 00151 struct matrix_singular : public domain_error 00152 { 00154 explicit matrix_singular(const char *s= "Matrix singular in solver.") 00155 : domain_error(s) {} 00156 }; 00157 00159 struct missing_diagonal : public domain_error 00160 { 00162 explicit missing_diagonal(const char *s= "Diagonal entry missing or not where it belongs to.") 00163 : domain_error(s) {} 00164 }; 00165 00167 struct access_during_insertion : public domain_error 00168 { 00170 explicit access_during_insertion(const char *s= "Diagonal entry missing or not where it belongs to.") 00171 : domain_error(s) {} 00172 }; 00173 00175 struct unexpected_result : public domain_error 00176 { 00178 explicit unexpected_result(const char *s= "The result of an operation is not the expected one.") 00179 : domain_error(s) {} 00180 }; 00181 00183 struct runtime_error : public std::runtime_error 00184 { 00186 explicit runtime_error(const char *s= "Run-time error") : std::runtime_error(s) {} 00187 }; 00188 00190 struct logic_error : public std::logic_error 00191 { 00193 explicit logic_error(const char *s= "Logic error") : std::logic_error(s) {} 00194 }; 00195 00196 } // namespace mtl 00197 00198 #endif // MTL_MTL_EXCEPTION_INCLUDE