exception.h
Go to the documentation of this file.
1 //-------------------------------------------------------------------
2 // Nano RPC
3 // https://github.com/tdv/nanorpc
4 // Created: 05.2018
5 // Copyright (C) 2018 tdv
6 //-------------------------------------------------------------------
7 
8 #ifndef __NANO_RPC_CORE_EXCEPTION_H__
9 #define __NANO_RPC_CORE_EXCEPTION_H__
10 
11 // STD
12 #include <iostream>
13 #include <stdexcept>
14 #include <string>
15 
16 #define NANORPC_EXCEPTION_DECL(class_, base_) \
17  class class_ \
18  : public base_ \
19  { \
20  public: \
21  using base_type = base_; \
22  using base_type :: base_type; \
23  };
24 
25 #define NANORPC_EXCEPTION_DECL_WITH_NAMESPACE(namespace_, class_, base_) \
26  namespace namespace_ \
27  { \
28  NANORPC_EXCEPTION_DECL(class_, base_) \
29  }
30 
31 namespace nanorpc
32 {
33 namespace core
34 {
35 namespace exception
36 {
37 
38 
39 NANORPC_EXCEPTION_DECL(nanorpc, std::runtime_error)
45 
46 inline std::string to_string(std::exception const &e)
47 {
48  std::string message = e.what();
49 
50  try
51  {
52  std::rethrow_if_nested(e);
53  }
54  catch (std::exception const &ex)
55  {
56  message += "\n";
57  message += "\t";
58  message += to_string(ex);
59  }
60 
61  return message;
62 }
63 
64 inline void default_error_handler(std::exception_ptr e)
65 {
66  if (!e)
67  return;
68 
69  try
70  {
71  std::rethrow_exception(e);
72  }
73  catch (std::exception const &ex)
74  {
75  std::cerr << "NanoRPC exception message: " << to_string(ex) << std::endl;
76  }
77 }
78 
79 
80 } // namespace exception
81 } // namespace core
82 } // namespace nanorpc
83 
84 
85 #endif // !__NANO_RPC_CORE_EXCEPTION_H__
nanorpc
Definition: client.h:30
nanorpc::core::server
Definition: server.h:40
nanorpc::core::exception::to_string
std::string to_string(std::exception const &e)
Definition: exception.h:46
nanorpc::core::exception::default_error_handler
void default_error_handler(std::exception_ptr e)
Definition: exception.h:64
std
Definition: Node.hpp:366
nanorpc::core::client
Definition: client.h:36
NANORPC_EXCEPTION_DECL
#define NANORPC_EXCEPTION_DECL(class_, base_)
Definition: exception.h:16


depthai
Author(s): Martin Peterlin
autogenerated on Sat Mar 22 2025 02:58:19