00001
00005
00006
00007
00008
00009
00010 #ifndef TBCI_EXCEPT_H
00011 #define TBCI_EXCEPT_H
00012
00013 #include "basics.h"
00014 #include <cstring>
00015 #ifndef HAVE_NO_NEW_HEADERS_BUG
00016 # include <exception>
00017 #else
00018 # include <exception.h>
00019 #endif
00020
00021 NAMESPACE_TBCI
00022
00058 class NumErr : public STD__ exception
00059 {
00060 public:
00062 const char* errtext;
00064 long index;
00065 NumErr()
00066 : STD__ exception()
00067 , errtext(strdup("Error in TBCI Numerical Library"))
00068 , index(0)
00069 {}
00070 NumErr(const char* txt, const long idx = 0)
00071 : STD__ exception()
00072 , errtext(strdup(txt))
00073 , index(idx)
00074 {}
00075 NumErr(const std::string &str, const long idx = 0)
00076 : STD__ exception()
00077 , errtext(str.c_str())
00078 , index(idx)
00079 {}
00080 NumErr(const NumErr& ne)
00081 : STD__ exception(ne)
00082 , errtext(strdup(ne.errtext))
00083 , index(ne.index)
00084 {}
00085 virtual const char* what() const throw()
00086 { return errtext; }
00087 virtual ~NumErr() throw()
00088 { CSTD__ free((void*)errtext); }
00089
00090 };
00091
00092 #ifdef ERRCHECK
00093
00094 #define __TBCIERR_BUF_SZ 128
00095 #ifdef HAVE_WEAK_ATTR // Try to have only once
00096 char err_bf[__TBCIERR_BUF_SZ] WEAKA;
00097
00098 volatile unsigned err_ptr WEAKA;
00099 #else
00100 static char err_bf[__TBCIERR_BUF_SZ];
00101 static volatile unsigned err_ptr;
00102 #endif
00103 static char* ltoa(const long l)
00104 {
00105 unsigned oldptr = err_ptr;
00106 err_ptr += sprintf(err_bf+oldptr, "%li", l) + 1;
00107 if (err_ptr >= __TBCIERR_BUF_SZ-16)
00108 err_ptr = 0;
00109 return err_bf+oldptr;
00110 }
00111 #endif
00112
00113 NAMESPACE_END
00114
00115 #endif
00116