TBCI Numerical high perf. C++ Library  2.8.0
except.h
Go to the documentation of this file.
1 
5 //To be included AFTER or FROM basics.h !!!
6 
7 // Last change: 30/6/97 KG
8 /* $Id: except.h,v 1.6.2.11 2019/05/28 15:11:09 garloff Exp $ */
9 
10 #ifndef TBCI_EXCEPT_H
11 #define TBCI_EXCEPT_H
12 
13 #include "tbci/basics.h"
14 #include <cstring>
15 #ifndef HAVE_NO_NEW_HEADERS_BUG
16 # include <exception>
17 #else
18 # include <exception.h>
19 #endif
20 
22 
58 class NumErr : public STD__ exception
59 {
60  public:
62  const char* errtext;
64  long index;
66  : STD__ exception()
67  , errtext(strdup("Error in TBCI Numerical Library"))
68  , index(0)
69  {}
70  NumErr(const char* txt, const long idx = 0)
71  : STD__ exception()
72  , errtext(strdup(txt))
73  , index(idx)
74  {}
75  NumErr(const std::string &str, const long idx = 0)
76  : STD__ exception()
77  , errtext(str.c_str())
78  , index(idx)
79  {}
80  NumErr(const NumErr& ne)
81  : STD__ exception(ne)
82  , errtext(strdup(ne.errtext))
83  , index(ne.index)
84  {}
85  virtual const char* what() const throw()
86  { return errtext; }
87  virtual ~NumErr() throw()
88  { CSTD__ free((void*)errtext); }
89 
90 };
91 
92 // We need a long to ascii conversion
93 #define __TBCIERR_BUF_SZ 256
94 #ifdef HAVE_WEAK_ATTR // Try to have only once
96 // racy in multithreaded env but we don't care
97 volatile unsigned err_ptr WEAKA;
98 #else
99 static char err_bf[__TBCIERR_BUF_SZ];
100 static volatile unsigned err_ptr;
101 #endif
102 static char* ltoa(const long l)
103 {
104  unsigned oldptr = err_ptr;
105  err_ptr += sprintf(err_bf+oldptr, "%li", l) + 1;
106  if (err_ptr >= __TBCIERR_BUF_SZ-16)
107  err_ptr = 0;
108  return err_bf+oldptr;
109 }
110 
111 #ifdef HAVE_NOEXCEPT_FALSE
112 # define THROWEXCEPT noexcept(false)
113 #else
114 # define THROWEXCEPT
115 #endif
116 
118 
119 #endif /* TBCI_EXCEPT_H */
120 
static char err_bf[256]
Definition: except.h:99
NumErr()
Definition: except.h:65
#define NAMESPACE_TBCI
Definition: basics.h:317
exception base class for the TBCI NumLib
Definition: except.h:58
static volatile unsigned err_ptr
Definition: except.h:100
NAMESPACE_END NAMESPACE_TBCI unsigned int tbci_control WEAKA
Definition: smp.cc:1133
NumErr(const char *txt, const long idx=0)
Definition: except.h:70
virtual ~NumErr()
Definition: except.h:87
NumErr(const std::string &str, const long idx=0)
Definition: except.h:75
const char * errtext
Short error description in _what.
Definition: except.h:62
#define CSTD__
Definition: basics.h:340
static char * ltoa(const long l)
Definition: except.h:102
#define __TBCIERR_BUF_SZ
Definition: except.h:93
#define STD__
Definition: basics.h:338
#define NAMESPACE_END
Definition: basics.h:323
NumErr(const NumErr &ne)
Definition: except.h:80
long index
Index for out of bounds error.
Definition: except.h:64
virtual const char * what() const
Definition: except.h:85