STIR  6.2.0
StirException.h
1 #ifndef STIR_EXCEPTION
2 #define STIR_EXCEPTION
3 
4 #include <string.h>
5 
6 #include <exception>
7 #include <iostream>
8 
9 class StirException : public std::exception
10 {
11 public:
12  StirException(const char* reason, const char* file, int line)
13  {
14  size_t len = strlen(reason) + 1;
15  _reason = new char[len];
16  memcpy(_reason, reason, len);
17  len = strlen(file) + 1;
18  _file = new char[len];
19  memcpy(_file, file, len);
20  _line = line;
21  }
22  virtual ~StirException() throw()
23  {
24  delete[] _reason;
25  delete[] _file;
26  }
27  virtual const char* what() const throw() { return _reason; }
28  const char* file() const throw() { return _file; }
29  int line() const throw() { return _line; }
30 
31 private:
32  char* _reason;
33  char* _file;
34  int _line;
35 };
36 
37 #endif