SSCMA-Micro CPP SDK  v2.0.0
SSCMA-Micro is a cross-platform machine learning inference framework designed for embedded devices.
ma_exception.h
Go to the documentation of this file.
1 #ifndef _MA_EXCEPTION_H_
2 #define _MA_EXCEPTION_H_
3 
4 #ifdef __cplusplus
5 #include <string>
6 #endif
7 
8 #include "ma_config_internal.h"
9 #include "ma_types.h"
10 
11 #ifdef __cplusplus
12 
13 namespace ma {
14 
15 #if MA_USE_EXCEPTION
16 class Exception : public std::exception {
17 private:
18  ma_err_t err_;
19  std::string msg_;
20 
21 public:
22  Exception(ma_err_t err, const std::string& msg) : err_(err), msg_(msg) {}
23  ma_err_t err() const {
24  return err_;
25  }
26  const char* what() const noexcept override {
27  return msg_.c_str();
28  }
29 };
30 
31 #define MA_TRY try
32 #define MA_THROW(e) throw e
33 #define MA_CATCH(x) catch (x)
34 #else
35 class Exception {
36 private:
37  ma_err_t err_;
38  std::string msg_;
39 
40 public:
41  Exception(ma_err_t err, const std::string& msg) : err_(err), msg_(msg) {}
42  ma_err_t err() const {
43  return err_;
44  }
45  const char* what() const noexcept {
46  return msg_.c_str();
47  }
48 };
49 
50 #define MA_TRY if (true)
51 #define MA_THROW(e)
52 #define MA_CATCH(x) if (e.err() != MA_OK)
53 #endif
54 } // namespace ma
55 
56 #endif
57 
58 #endif // _MA_EXCEPTION_H_
ma_err_t
Definition: ma_types.h:21
Definition: ma_cv.cpp:7