include/common/exception.h
Go to the documentation of this file.
1 //
2 // C++ Interface: exception
3 //
4 // Description:
5 //
6 //
7 // Author: Tiziano Müller <tiziano.mueller@neuronics.ch>, (C) 2006
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 //
11 //
12 
13 #ifndef _EXCEPTION_H_
14 #define _EXCEPTION_H_
15 
16 
17 #include <string>
18 #include "dllexport.h"
19 
20 
21 #ifdef HAVE_LIBEBT
22 
23 #include <libebt/libebt.hh>
24 #include <libebt/libebt_util.hh>
25 
26 struct ExceptionTag { };
27 typedef libebt::BacktraceContext<ExceptionTag, std::string> Context;
28 
29 
34 
35 class DLLDIR Exception : public libebt::Backtraceable<ExceptionTag>,
36  public std::exception {
37  protected:
38  const std::string _message;
39  const int _error_number;
40 
41  public:
42  Exception(const std::string & message, const int error_number) throw () :
43  libebt::Backtraceable<ExceptionTag>(),
44  std::exception(),
45  _message(message), _error_number(error_number) {
46  }
47 
48  virtual ~Exception() throw () {
49  }
50 
51  std::string message() const throw() {
52  return _message;
53  }
54  const char* what() const throw() {
55  return _message.c_str();
56  }
57 
58  const int error_number() const throw() {
59  return _error_number;
60  }
61 };
62 
66 
67 #else // HAVE_LIBEBT
68 
73 
74 // The compiler should optimize that away
75 struct DLLDIR Context {
76  Context(const char*) {}
77 };
78 
79 class DLLDIR Exception : public std::exception {
80  protected:
81  const std::string _message;
82  const int _error_number;
83 
84  public:
85  Exception(const std::string & message, const int error_number) throw () :
86  std::exception(),
87  _message(message), _error_number(error_number) {
88  }
89 
90  virtual ~Exception() throw () {
91  }
92 
93  std::string message() const throw() {
94  return _message;
95  }
96  const char* what() const throw() {
97  return _message.c_str();
98  }
99 
100  int error_number() const throw() {
101  return _error_number;
102  }
103 };
104 
108 
109 
110 #endif
111 
112 #endif
const std::string _message
std::string message() const
#define DLLDIR
Definition: dllexport.h:30
Exception(const std::string &message, const int error_number)
Context(const char *)
BaseException Exception
Definition: myexcept.h:98
const char * what() const
int error_number() const


kni
Author(s): Martin Günther
autogenerated on Fri Jan 3 2020 04:01:16