Face SDK  1.7 Mozart rc
Face Recognition Software Development Kit
exception.h
Go to the documentation of this file.
1 
4 #ifndef FACE_SDK_EXCEPTION_H
5 #define FACE_SDK_EXCEPTION_H
6 
7 #include <face_sdk_base/export.h>
8 
9 #include <exception>
10 #include <string>
11 
12 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32)
13 #pragma warning(push)
14 
15 // For correct working on android platform need to export face_sdk::exception.
16 // In other case we will have RTTI problems in out tests.
17 // Since we have exported face_sdk_exception, it is also good to export
18 // the symbol of the classes that are used inside the class, in out case class std::string.
19 // We couldn't do that. Prefer to disable this warning.
20 #pragma warning(disable:4275)
21 #pragma warning(disable:4251)
22 #endif
23 
24 namespace face_sdk
25 {
56  class FACE_SDK_EXPORT exception : public std::exception
57  {
58  public:
59 
60  exception();
61 
62  exception(const std::string& message);
63 
64  std::string type_name() const;
65 
66  virtual const char* what() const noexcept override;
67 
68  protected:
69 
70  std::string _message;
71  std::string _type_name;
72  };
73 
74 #define DEFINE_FACE_SDK_EXCEPTION(x) \
75  \
76  class FACE_SDK_EXPORT x : public exception \
77  { \
78  public: \
79  x() : exception() \
80  { _type_name = std::string(#x); } \
81  \
82  explicit x(const std::string &message) \
83  : exception(message) \
84  { _type_name = std::string(#x); } \
85  }
86 
87  DEFINE_FACE_SDK_EXCEPTION(runtime_exception);
88 
89  DEFINE_FACE_SDK_EXCEPTION(internal_error_exception);
90 
91  DEFINE_FACE_SDK_EXCEPTION(out_of_range_exception);
92 
93  DEFINE_FACE_SDK_EXCEPTION(invalid_parameter_exception);
94 
95  DEFINE_FACE_SDK_EXCEPTION(file_exception);
96 
97  DEFINE_FACE_SDK_EXCEPTION(file_not_found_exception);
98 
99  DEFINE_FACE_SDK_EXCEPTION(bad_image_data_exception);
100 
101  DEFINE_FACE_SDK_EXCEPTION(bad_image_format_exception);
102 
103  DEFINE_FACE_SDK_EXCEPTION(signature_mismatch_exception);
104 
105  DEFINE_FACE_SDK_EXCEPTION(incompatible_version_exception);
106 
107  DEFINE_FACE_SDK_EXCEPTION(version_not_available_exception);
108 
109  DEFINE_FACE_SDK_EXCEPTION(key_not_found_exception);
110 
111  DEFINE_FACE_SDK_EXCEPTION(key_exists_exception);
112 
113  DEFINE_FACE_SDK_EXCEPTION(data_container_corrupted_exception);
114 
115  DEFINE_FACE_SDK_EXCEPTION(data_container_entries_limit_exceed_exception);
116 
117  DEFINE_FACE_SDK_EXCEPTION(not_implemented_exception);
118 
119  DEFINE_FACE_SDK_EXCEPTION(license_exception);
120 
121  DEFINE_FACE_SDK_EXCEPTION(nvml_exception);
122 
123  DEFINE_FACE_SDK_EXCEPTION(platofrm_not_supported_exception);
124 
125  DEFINE_FACE_SDK_EXCEPTION(not_supported_exception);
126 
127  class FACE_SDK_EXPORT upscale_too_much_exception : public exception
128  {
129  private:
130  uint32_t _idx;
131  public:
132  upscale_too_much_exception(const std::string &message, uint32_t idx) : exception(message)
133  {
134  _type_name = "upscale_too_much_exception";
135  _idx = idx;
136  }
137 
138  uint32_t imageIdx()
139  {
140  return _idx;
141  }
142  };
143 
144 
145  std::string FACE_SDK_EXPORT format_exception(const face_sdk::exception& e, int level = 0);
146 
147  bool FACE_SDK_EXPORT is_root_exception_of_type(const std::type_info &tp, const face_sdk::exception &e);
148 
149  void FACE_SDK_EXPORT rethrow_root_exception(const face_sdk::exception& e);
150 
153 #define FACE_SDK_RETHROW_ROOT(x) try{ x; } catch (const face_sdk::exception &exp ) { rethrow_root_exception(exp); }
154 }
155 
156 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32)
157 #pragma warning(pop)
158 #endif
159 
160 #endif //FACE_SDK_EXCEPTION_H
face_sdk::exception
Base FaceSDK exception class. Almost all exceptions that FaceSDK throws are inherits this class.
Definition: exception.h:56
export.h