]> git.sur5r.net Git - openldap/blobdiff - contrib/ldapc++/src/LDAPException.cpp
derive LDAPException from std::exception, merged ReferralException into the
[openldap] / contrib / ldapc++ / src / LDAPException.cpp
index ce8ccc48737520155372b7b562aecf75f1fc641b..ac679203cedccc4e2182ad227b3a1f22ab0407f8 100644 (file)
@@ -8,19 +8,23 @@
 #include <ldap.h>
 #include "config.h"
 #include "LDAPException.h"
-#include "LDAPReferralException.h"
 
 #include "LDAPAsynConnection.h"
+#include "LDAPResult.h"
 
 using namespace std;
 
-LDAPException::LDAPException(int res_code, const string& err_string){
+LDAPException::LDAPException(int res_code, const string& err_string) throw()
+    : std::runtime_error(err_string)
+{
        m_res_code=res_code;
        m_res_string=string(ldap_err2string(res_code));
     m_err_string=err_string;
 }
 
-LDAPException::LDAPException(const LDAPAsynConnection *lc){
+LDAPException::LDAPException(const LDAPAsynConnection *lc) throw()
+    : std::runtime_error("")
+{
     LDAP *l = lc->getSessionHandle();
     ldap_get_option(l,LDAP_OPT_RESULT_CODE,&m_res_code);
     const char *res_cstring = ldap_err2string(m_res_code);
@@ -43,22 +47,32 @@ LDAPException::LDAPException(const LDAPAsynConnection *lc){
     }
 }
 
-LDAPException::~LDAPException(){
+LDAPException::~LDAPException() throw()
+{
 }
 
-int LDAPException::getResultCode() const{
+int LDAPException::getResultCode() const throw()
+{
        return m_res_code;
 }
 
-const string& LDAPException::getResultMsg() const{
+const string& LDAPException::getResultMsg() const throw()
+{
        return m_res_string;
 }
 
-const string& LDAPException::getServerMsg() const{
+const string& LDAPException::getServerMsg() const throw()
+{
     return m_err_string;
 }
 
-ostream& operator << (ostream& s, LDAPException e){
+const char* LDAPException::what() const throw()
+{
+    return this->m_res_string.c_str(); 
+}
+
+ostream& operator << (ostream& s, LDAPException e) throw()
+{
        s << "Error " << e.m_res_code << ": " << e.m_res_string;
        if (!e.m_err_string.empty()) {
                s << endl <<  "additional info: " << e.m_err_string ;
@@ -66,3 +80,18 @@ ostream& operator << (ostream& s, LDAPException e){
        return s;
 }
 
+
+LDAPReferralException::LDAPReferralException(const LDAPUrlList& urls) throw() 
+        : LDAPException(LDAPResult::REFERRAL) , m_urlList(urls)
+{
+}
+
+LDAPReferralException::~LDAPReferralException() throw()
+{
+}
+
+const LDAPUrlList& LDAPReferralException::getUrls() throw()
+{
+    return m_urlList;
+}
+