一个自定义的c++错误类 和 同步异步、阻塞非阻塞(区别简述)

 一个例子,自定义exception 继承std::exception

 1 class _oct_udp_api_export_ udp_err : public std::exception
 2     {
 3     public:
 4         explicit udp_err(std::string str_err);
 5         virtual ~udp_err();
 6         udp_err(const udp_err& instance) = delete;
 7         udp_err& operator = (const udp_err& instance) = delete;
 8         udp_err(const udp_err&& instance) = default;
 9         udp_err& operator = (const udp_err&& instance) = default;
10 
11 
12         // -------------------------------------------------------------------------------
13 
14 
15         /* @ brief: initialize properties of udp_err
16         *  @ const std::string str_err - the string to initialize
17         *  @ return - int
18                 0 - success
19         */
20         int init(const std::string str_err);
21 
22 
23         /* @ brief: to get error string of current.
24         *  @ return - std::string
25                 std::string str - error, its default value is empty
26         */
27         std::string get_error_str();
28 
29     private:
30         std::string _str_err;
31     };

 

同步异步、阻塞非阻塞的区别:

同步IO和异步IO的区别就在于:数据访问的时候进程是否阻塞

阻塞IO和非阻塞IO的区别就在于:应用程序的调用是否立即返回

 

posted @ 2020-08-26 15:21  mohist  阅读(329)  评论(0编辑  收藏  举报