icedb  version 0.5.1
Snow particle scattering database API
error.hpp
Go to the documentation of this file.
1 #pragma once
2 #include "defs.h"
3 #include <exception>
4 #include <memory>
5 #include <string>
6 #include "optionsForwards.hpp"
7 #include "errorTypes.hpp"
8 #include "error.h"
9 
10 namespace icedb {
11  namespace error {
12  class error_options_inner;
13  class xError;
14  typedef std::shared_ptr<xError> xError_ptr;
17  class xError : public std::exception
18  {
19  protected:
20  std::shared_ptr<error_options_inner> ep;
21  public:
23  virtual ~xError();
24  virtual const char* what() const noexcept;
25 
27  //void push(::icedb::registry::const_options_ptr);
28  xError& push(::icedb::registry::options_ptr);
29  xError& push();
30 
31  template <class T> xError& add(const std::string &key, const T value);
32 
33  };
34 
35 
36 
37  // The C++ interface to the C-style (non-exceptions) errors:
38  // These C++ functions may throw exceptions. Their C counterparts will not.
39  // The possible exceptions involve use of shared pointers and C++ strings.
40 
43 
44  DL_ICEDB void stringify(error_code_t err, std::string &);
45  DL_ICEDB void stringify(error_code_t err, char* const*);
46  template <class StringType> StringType stringify(error_code_t err) { return StringType(); }
47  template<> DL_ICEDB std::string stringify(error_code_t err);
48  //extern template std::string stringify<std::string>(error_code_t err);
49  template<> DL_ICEDB const char* stringify(error_code_t err);
50  //extern template const char* stringify<const char*>(error_code_t err);
51 
56  typedef std::shared_ptr<ICEDB_error_context> error_context_pt;
57 
60  DL_ICEDB error_context_pt get_error_context_thread_local();
61 
63  DL_ICEDB error_code_t error_context_to_code(const error_context_pt&);
64 
65  DL_ICEDB void stringify(const error_context_pt &err, std::string &);
66  DL_ICEDB std::string stringify(const error_context_pt &err);
67 
68  }
69 }
70 
71 #ifdef _MSC_FULL_VER
72 #define ICEDB_FUNCSIG __FUNCSIG__
73 #endif
74 #ifdef __GNUC__
75 #define ICEDB_FUNCSIG __PRETTY_FUNCTION__
76 #endif
77 
78 #define ICEDB_RSpushErrorvars \
79  .add<std::string>("source_filename", std::string(__FILE__)) \
80  .add<int>("source_line", (int)__LINE__) \
81  .add<std::string>("source_function", std::string(ICEDB_FUNCSIG))
82 #define ICEDB_RSmkError(x) ::icedb::error::xError(x).push() \
83  ICEDB_RSpushErrorvars
84 #define ICEDB_throw(x) throw ICEDB_RSmkError(x)
std::shared_ptr< xError > xError_ptr
Definition: error.hpp:13
#define DL_ICEDB
Definition: defs.h:124
DL_ICEDB error_code_t error_context_to_code(const error_context_pt &err)
Definition: error.cpp:327
std::shared_ptr< ICEDB_error_context > error_context_pt
Definition: error.hpp:56
STL namespace.
virtual const char * what() const noexcept
Definition: error.cpp:242
ICEDB_error_code error_code_t
Definition: error.hpp:42
DL_ICEDB void stringify(error_code_t err, std::string &res)
Definition: error.cpp:307
xError & add(const std::string &key, const T value)
Definition: error.cpp:271
DL_ICEDB error_context_pt get_error_context_thread_local()
Definition: error.cpp:303
std::shared_ptr< error_options_inner > ep
Definition: error.hpp:20
xError & push()
Definition: error.cpp:263
std::shared_ptr< options > options_ptr
xError(error_types=error_types::xOtherError)
Definition: error.cpp:237
int ICEDB_error_code
Definition: error.h:17
virtual ~xError()
Definition: error.cpp:241