1 #ifndef CONNECT___NCBI_CONN_EXCEPTION__HPP
2 #define CONNECT___NCBI_CONN_EXCEPTION__HPP
3 
4 /* $Id: ncbi_conn_exception.hpp 604946 2020-04-04 23:31:35Z lavr $
5  * ===========================================================================
6  *
7  *                            PUBLIC DOMAIN NOTICE
8  *               National Center for Biotechnology Information
9  *
10  *  This software/database is a "United States Government Work" under the
11  *  terms of the United States Copyright Act.  It was written as part of
12  *  the author's official duties as a United States Government employee and
13  *  thus cannot be copyrighted.  This software/database is freely available
14  *  to the public for use. The National Library of Medicine and the U.S.
15  *  Government have not placed any restriction on its use or reproduction.
16  *
17  *  Although all reasonable efforts have been taken to ensure the accuracy
18  *  and reliability of the software and data, the NLM and the U.S.
19  *  Government do not and cannot warrant the performance or results that
20  *  may be obtained by using this software or data. The NLM and the U.S.
21  *  Government disclaim all warranties, express or implied, including
22  *  warranties of performance, merchantability or fitness for any particular
23  *  purpose.
24  *
25  *  Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Author:  Anton Lavrentiev
30  *
31  * File Description:
32  *   CONN-library exception type
33  *
34  */
35 
36 #include <corelib/ncbiexpt.hpp>
37 #include <connect/ncbi_core.h>
38 
39 
40 /** @addtogroup ConnExcep
41  *
42  * @{
43  */
44 
45 
46 BEGIN_NCBI_SCOPE
47 
48 
49 /// Generic CONN exception.
50 ///
51 class NCBI_XCONNECT_EXPORT CConnException
52     : EXCEPTION_VIRTUAL_BASE public CException
53 {
54 public:
55     enum EErrCode {
56         eConn ///< Unspecified connect problem
57     };
58     virtual const char* GetErrCodeString(void) const override;
59     NCBI_EXCEPTION_DEFAULT(CConnException, CException);
60 };
61 
62 
63 /// I/O exception.
64 ///
65 /// @sa EIO_Status
66 class NCBI_XCONNECT_EXPORT CIO_Exception
67     : EXCEPTION_VIRTUAL_BASE public CConnException
68 {
69 public:
70     /// @sa EIO_Status
71     enum EErrCode {
72         eTimeout      = eIO_Timeout,
73         eInterrupt    = eIO_Interrupt,
74         eInvalidArg   = eIO_InvalidArg,
75         eNotSupported = eIO_NotSupported,
76         eUnknown      = eIO_Unknown,
77         eClosed       = eIO_Closed
78     };
79     virtual const char* GetErrCodeString(void) const override;
80     NCBI_EXCEPTION_DEFAULT(CIO_Exception, CConnException);
81 };
82 
83 
84 /// Check EIO_Status, throw an exception if something is wrong
85 ///
86 /// @sa EIO_Status
87 #define NCBI_IO_CHECK(errnum)                                           \
88     do {                                                                \
89         if ((errnum) != eIO_Success) {                                  \
90             THROWp_TRACE(CIO_Exception,                                 \
91                          (DIAG_COMPILE_INFO, 0,                         \
92                           CIO_Exception::EErrCode(errnum),              \
93                           "I/O error"));                                \
94         }                                                               \
95     } while (0)
96 
97 
98 END_NCBI_SCOPE
99 
100 
101 /* @} */
102 
103 #endif  /* CONNECT___NCBI_CONN_EXCEPTION__HPP */
104