DeviceAtlas C++ Api documentation
exception.h
1 #ifndef MTLD_EXCEPTION
2 #define MTLD_EXCEPTION
3 
4 #if defined(__unix__)
5 #include <sys/param.h>
6 #endif
7 #include <exception>
8 #include <sstream>
9 #include <string>
10 #include <errno.h>
11 
12 namespace Mobi { namespace Mtld {
13 
14 // An extension of std::exception
15 
16 class Exception : public std::exception {
17  std::stringstream stream;
18  mutable std::string str;
19 public:
20  std::ostream &out() { return stream; }
21  const char *what() const throw() { str = stream.str(); return str.c_str(); }
22  virtual ~Exception() throw() {}
23  Exception(std::string info) { stream << info; }
24  Exception() {}
25  Exception(const Exception &rhs) : std::exception(rhs) {
26  stream << rhs.what();
27  }
28 };
29 
30 template <typename T>
31 Exception &operator<<(Exception &e, const T &t) {
32  e.out() << t;
33  return e;
34 }
35 
36 }}
37 
38 #endif
Definition: exception.h:16
Definition: binary.h:13