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