First public contribution.
2 // Copyright (c) 2000-2002
3 // Joerg Walter, Mathias Koch
5 // Permission to use, copy, modify, distribute and sell this software
6 // and its documentation for any purpose is hereby granted without fee,
7 // provided that the above copyright notice appear in all copies and
8 // that both that copyright notice and this permission notice appear
9 // in supporting documentation. The authors make no representations
10 // about the suitability of this software for any purpose.
11 // It is provided "as is" without express or implied warranty.
13 // The authors gratefully acknowledge the support of
14 // GeNeSys mbH & Co. KG in producing this work.
17 #ifndef _BOOST_UBLAS_EXCEPTION_
18 #define _BOOST_UBLAS_EXCEPTION_
20 #if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
25 #ifndef BOOST_UBLAS_NO_STD_CERR
29 #include <boost/numeric/ublas/detail/config.hpp>
31 namespace boost { namespace numeric { namespace ublas {
34 #if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
35 // Inherit from standard exceptions as requested during review.
36 : public std::runtime_error {
37 explicit divide_by_zero (const char *s = "divide by zero") :
38 std::runtime_error (s) {}
46 explicit divide_by_zero (const char *)
55 #if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
56 // Inherit from standard exceptions as requested during review.
57 : public std::logic_error {
58 explicit internal_logic (const char *s = "internal logic") :
59 std::logic_error (s) {}
67 explicit internal_logic (const char *)
76 #if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
77 // Inherit from standard exceptions as requested during review.
78 : public std::logic_error {
79 explicit external_logic (const char *s = "external logic") :
80 std::logic_error (s) {}
81 // virtual const char *what () const throw () {
82 // return "exception: external logic";
91 explicit external_logic (const char *)
100 #if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
101 // Inherit from standard exceptions as requested during review.
102 : public std::invalid_argument {
103 explicit bad_argument (const char *s = "bad argument") :
104 std::invalid_argument (s) {}
112 explicit bad_argument (const char *)
121 #if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
122 // Inherit from standard exceptions as requested during review.
123 : public std::domain_error {
124 explicit bad_size (const char *s = "bad size") :
125 std::domain_error (s) {}
133 explicit bad_size (const char *)
142 #if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
143 // Inherit from standard exceptions as requested during review.
144 : public std::out_of_range {
145 explicit bad_index (const char *s = "bad index") :
146 std::out_of_range (s) {}
154 explicit bad_index (const char *)
163 #if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
164 // Inherit from standard exceptions as requested during review.
165 : public std::runtime_error {
166 explicit singular (const char *s = "singular") :
167 std::runtime_error (s) {}
175 explicit singular (const char *)
185 #if ! defined (BOOST_NO_EXCEPTIONS) && ! defined (BOOST_UBLAS_NO_EXCEPTIONS)
186 // Inherit from standard exceptions as requested during review.
187 : public std::domain_error {
188 explicit non_real (const char *s = "exception: non real") :
189 std::domain_error (s) {}
197 explicit non_real (const char *)
205 #if BOOST_UBLAS_CHECK_ENABLE
206 // Macros are equivilent to
208 // BOOST_UBLAS_INLINE
209 // void check (bool expression, const E &e) {
214 // BOOST_UBLAS_INLINE
215 // void check_ex (bool expression, const char *file, int line, const E &e) {
219 #ifndef BOOST_UBLAS_NO_STD_CERR
220 #define BOOST_UBLAS_CHECK_FALSE(e) \
221 std::cerr << "Check failed in file " << __FILE__ << " at line " << __LINE__ << ":" << std::endl; \
223 #define BOOST_UBLAS_CHECK(expression, e) \
224 if (! (expression)) { \
225 std::cerr << "Check failed in file " << __FILE__ << " at line " << __LINE__ << ":" << std::endl; \
226 std::cerr << #expression << std::endl; \
229 #define BOOST_UBLAS_CHECK_EX(expression, file, line, e) \
230 if (! (expression)) { \
231 std::cerr << "Check failed in file " << (file) << " at line " << (line) << ":" << std::endl; \
232 std::cerr << #expression << std::endl; \
236 #define BOOST_UBLAS_CHECK_FALSE(e) \
238 #define BOOST_UBLAS_CHECK(expression, e) \
239 if (! (expression)) { \
242 #define BOOST_UBLAS_CHECK_EX(expression, file, line, e) \
243 if (! (expression)) { \
248 // Macros are equivilent to
250 // BOOST_UBLAS_INLINE
251 // void check (bool expression, const E &e) {}
253 // BOOST_UBLAS_INLINE
254 // void check_ex (bool expression, const char *file, int line, const E &e) {}
255 #define BOOST_UBLAS_CHECK_FALSE(e)
256 #define BOOST_UBLAS_CHECK(expression, e)
257 #define BOOST_UBLAS_CHECK_EX(expression, file, line, e)
261 #ifndef BOOST_UBLAS_USE_FAST_SAME
262 // Macro is equivilent to
264 // BOOST_UBLAS_INLINE
265 // const T &same_impl (const T &size1, const T &size2) {
266 // BOOST_UBLAS_CHECK (size1 == size2, bad_argument ());
267 // return (std::min) (size1, size2);
269 // #define BOOST_UBLAS_SAME(size1, size2) same_impl ((size1), (size2))
272 // Kresimir Fresl and Dan Muller reported problems with COMO.
273 // We better change the signature instead of libcomo ;-)
274 // const T &same_impl_ex (const T &size1, const T &size2, const char *file, int line) {
275 T same_impl_ex (const T &size1, const T &size2, const char *file, int line) {
276 BOOST_UBLAS_CHECK_EX (size1 == size2, file, line, bad_argument ());
277 return (std::min) (size1, size2);
279 #define BOOST_UBLAS_SAME(size1, size2) same_impl_ex ((size1), (size2), __FILE__, __LINE__)
281 // Macros are equivilent to
283 // BOOST_UBLAS_INLINE
284 // const T &same_impl (const T &size1, const T &size2) {
287 // #define BOOST_UBLAS_SAME(size1, size2) same_impl ((size1), (size2))
288 #define BOOST_UBLAS_SAME(size1, size2) (size1)