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