]> git.sur5r.net Git - openldap/blob - contrib/ldapc++/src/LDAPException.h
derive LDAPException from std::exception, merged ReferralException into the
[openldap] / contrib / ldapc++ / src / LDAPException.h
1 /*
2  * Copyright 2000, OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5
6
7 #ifndef LDAP_EXCEPTION_H
8 #define LDAP_EXCEPTION_H
9
10 #include <iostream>
11 #include <string>
12 #include <stdexcept>
13
14 #include <LDAPUrlList.h>
15
16 class LDAPAsynConnection;
17
18 /**
19  * This class is only thrown as an Exception and used to signalize error
20  * conditions during LDAP-operations
21  */
22 class LDAPException : public std::runtime_error
23 {
24                 
25     public :
26         /**
27          * Constructs a LDAPException-object from the parameters
28          * @param res_code A valid LDAP result code.
29          * @param err_string    An addional error message for the error
30          *                      that happend (optional)
31          */
32         LDAPException(int res_code, 
33                 const std::string& err_string=std::string()) throw();
34                 
35         /**
36          * Constructs a LDAPException-object from the error state of a
37          * LDAPAsynConnection-object
38          * @param lc A LDAP-Connection for that an error has happend. The
39          *          Constructor tries to read its error state.
40          */
41         LDAPException(const LDAPAsynConnection *lc) throw();
42
43         /**
44          * Destructor
45          */
46         virtual ~LDAPException() throw();
47
48         /**
49          * @return The Result code of the object
50          */
51         int getResultCode() const throw();
52
53         /**
54          * @return The error message that is corresponding to the result
55          *          code .
56          */
57         const std::string& getResultMsg() const throw();
58         
59         /**
60          * @return The addional error message of the error (if it was set)
61          */
62         const std::string& getServerMsg() const throw();
63
64         
65         virtual const char* what() const throw();
66
67         /**
68          * This method can be used to dump the data of a LDAPResult-Object.
69          * It is only useful for debugging purposes at the moment
70          */
71         friend std::ostream& operator << (std::ostream &s, LDAPException e) throw();
72
73     private :
74         int m_res_code;
75         std::string m_res_string;
76         std::string m_err_string;
77 };
78
79 /**
80  * This class extends LDAPException and is used to signalize Referrals
81  * there were received during synchronous LDAP-operations
82  */
83 class LDAPReferralException : public LDAPException
84 {
85
86     public :
87         /**
88          * Creates an object that is initialized with a list of URLs
89          */
90         LDAPReferralException(const LDAPUrlList& urls) throw();
91
92         /**
93          * Destructor
94          */
95         ~LDAPReferralException() throw();
96
97         /**
98          * @return The List of URLs of the Referral/Search Reference
99          */
100         const LDAPUrlList& getUrls() throw();
101
102     private :
103         LDAPUrlList m_urlList;
104 };
105
106 #endif //LDAP_EXCEPTION_H