Iris SDK  1.0
Iris Recognition Software Development Kit
exception.h
Go to the documentation of this file.
1 #pragma once
2 
6 #include <iris_base/export.h>
7 
8 #include <exception>
9 #include <string>
10 #include <typeinfo>
11 
12 namespace iris_sdk
13 {
14 
19 class IRIS_SDK_EXPORT base_exception : public std::exception
20 {
21 public:
22 
24 
25  base_exception(const std::string& message, uint64_t code);
26 
27  virtual ~base_exception() = default;
28 
29  std::string type_name() const;
30 
31  const char* what() const noexcept override;
32 
33  uint64_t code() const noexcept;
34 
35 protected:
36  std::string _message;
37  uint64_t _code;
38  std::string _type_name;
39 };
40 
41 #define DEFINE_IRIS_SDK_EXCEPTION(x, ERROR_CODE) \
42  \
43  class IRIS_SDK_EXPORT x : public base_exception \
44  { \
45  public: \
46  x() : base_exception() \
47  { _type_name = std::string(#x); } \
48  \
49  explicit x(const std::string &message) \
50  : base_exception(message, ERROR_CODE) \
51  { _type_name = std::string(#x); } \
52  }
53 
54 DEFINE_IRIS_SDK_EXCEPTION(runtime_error, 1);
55 
56 DEFINE_IRIS_SDK_EXCEPTION(file_not_found_error, 2);
57 
58 DEFINE_IRIS_SDK_EXCEPTION(file_error, 3);
59 
60 DEFINE_IRIS_SDK_EXCEPTION(invalid_parameter_error, 4);
61 
62 DEFINE_IRIS_SDK_EXCEPTION(key_exists_error, 5);
63 
64 DEFINE_IRIS_SDK_EXCEPTION(limit_exceed_error, 6);
65 
66 DEFINE_IRIS_SDK_EXCEPTION(license_error, 7);
67 
68 DEFINE_IRIS_SDK_EXCEPTION(data_container_corrupted_error, 8);
69 
70 DEFINE_IRIS_SDK_EXCEPTION(key_not_found_error, 9);
71 
72 DEFINE_IRIS_SDK_EXCEPTION(invalid_signature_error, 10);
73 
80 void IRIS_SDK_EXPORT rethrow_root_exception(base_exception &exc);
81 
88 std::string IRIS_SDK_EXPORT format_exception(const base_exception& exc, int level = 0);
89 
90 bool IRIS_SDK_EXPORT is_root_exception_of_type(const std::type_info &tp, const base_exception &e);
91 
92 #define RETHROW_ROOT(x) try{ x; } catch (iris_sdk::base_exception &e) { rethrow_root_exception(e); }
93 
94 #define RETHROW_IF_NESTED(x) try{ x; } catch (iris_sdk::base_exception &e) { std::rethrow_if_nested(e); }
95 }
The iris sdk base exception.
Definition: exception.h:19
void IRIS_SDK_EXPORT rethrow_root_exception(base_exception &exc)
Use function for throwing the bottom of nested exceptions stack.
Definition: codes.h:6
std::string IRIS_SDK_EXPORT format_exception(const base_exception &exc, int level=0)
Use function for building info message with the chain of nested exceptions stack. ...