GCS  0.2.3
gu_exception.hpp
1 /*
2  * Copyright (C) 2009 Codership Oy <info@codership.com>
3  *
4  */
5 
6 #ifndef __GU_EXCEPTION__
7 #define __GU_EXCEPTION__
8 
9 #include <string>
10 #include <exception>
11 #include "gu_errno.h"
12 
13 namespace gu {
14 
16  class NotSet {};
17  class NotFound {};
18 
19  class Exception: public std::exception
20  {
21  public:
22 
23  Exception (const std::string& msg_, int err_)
24  : msg (msg_),
25  err (err_)
26  {}
27 
28  virtual ~Exception () throw() {}
29 
30  const char* what () const throw() { return msg.c_str(); }
31 
32  int get_errno () const { return err; }
33 
34  void trace (const char* file, const char* func, int line);
35 
36  private:
37 
38  std::string msg;
39  const int err;
40  };
41 }
42 
43 /* to mark a place where exception was caught */
44 #define GU_TRACE(_exception_) _exception_.trace(__FILE__, __FUNCTION__, __LINE__)
45 
46 #ifndef NDEBUG /* enabled together with assert() */
47 
48 #define gu_trace(_expr_) \
49  try { _expr_; } catch (gu::Exception& e) { GU_TRACE(e); throw; }
50 
51 #else
52 
53 #define gu_trace(_expr_) _expr_
54 
55 #endif // NDEBUG
56 
57 #endif // __GU_EXCEPTION__
Definition: gu_exception.hpp:19
Definition: gu_exception.hpp:17
Definition: gu_exception.hpp:16