-
Notifications
You must be signed in to change notification settings - Fork 14
/
maix_err.hpp
121 lines (104 loc) · 3.25 KB
/
maix_err.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* @author neucrack@sipeed
* @copyright Sipeed Ltd 2023-
* @license Apache 2.0
* @update 2023.9.8: Add framework, create this file.
*/
#pragma once
#include <string>
namespace maix
{
namespace err
{
/**
* @brief Maix Error code
* @maixpy maix.err.Err
*/
enum Err
{
// !!! fixed error code, DO NOT change number already defined, only append new error code
ERR_NONE = 0, // No error
ERR_ARGS , // Invalid arguments
ERR_NO_MEM , // No memory
ERR_NOT_IMPL , // Not implemented
ERR_NOT_READY , // Not ready
ERR_NOT_INIT , // Not initialized
ERR_NOT_OPEN , // Not opened
ERR_NOT_PERMIT , // Not permitted
ERR_REOPEN , // Re-open
ERR_BUSY , // Busy
ERR_READ , // Read error
ERR_WRITE , // Write error
ERR_TIMEOUT , // Timeout
ERR_RUNTIME , // Runtime error
ERR_IO , // IO error
ERR_NOT_FOUND , // Not found
ERR_ALREAY_EXIST , // Already exist
ERR_BUFF_FULL , // Buffer full
ERR_BUFF_EMPTY , // Buffer empty
ERR_CANCEL , // Cancel
ERR_OVERFLOW , // Overflow
ERR_MAX,
}; // !! Change this please update err_str in maix_err.cpp too !!
/**
* @brief Maix Exception
* @maixpy maix.err.Exception
*/
class Exception : public std::exception
{
public:
Exception(const std::string &msg, err::Err code = err::ERR_NONE);
Exception(const err::Err code, const std::string &msg = "");
virtual const char *what() const throw();
err::Err code() const;
private:
std::string _msg;
err::Err _code;
};
/**
* Error code to string
* @param[in] e error code, err::Err type
* @return error string
* @maixpy maix.err.to_str
*/
std::string to_str(err::Err e);
/**
* @brief get last error string
* @return error string
* @maixpy maix.err.get_error
*/
std::string& get_error();
/**
* @brief set last error string
* @param[in] str error string
* @maixpy maix.err.set_error
*/
void set_error(const std::string &str);
/**
* @brief set last error string
* @param[in] str error string
*/
void set_error(const char *str);
/**
* Check error code, if not ERR_NONE, raise err.Exception
* @param[in] e error code, err::Err type
* @param[in] msg error message
* @maixpy maix.err.check_raise
*/
void check_raise(err::Err e, const std::string &msg = "");
/**
* Check condition, if false, raise err.Exception
* @param[in] ok condition, if true, do nothing, if false, raise err.Exception
* @param[in] msg error message
* @maixpy maix.err.check_bool_raise
*/
void check_bool_raise(bool ok, const std::string &msg = "");
/**
* Check NULL pointer, if NULL, raise exception
* @param[in] ptr pointer
* @param[in] msg error message
* @maixpy maix.err.check_null_raise
*/
void check_null_raise(void *ptr, const std::string &msg = "");
}; // namespace err
}; // namespace maix