disable-zoom configure option
[yazpp-moved-to-github.git] / zoom / zexcept.cpp
index 7113a4d..04e6665 100644 (file)
@@ -1,12 +1,11 @@
-// $Header: /home/cvsroot/yaz++/zoom/zexcept.cpp,v 1.1 2002-08-08 16:06:08 mike Exp $
+// $Header: /home/cvsroot/yaz++/zoom/zexcept.cpp,v 1.7 2002-11-30 22:33:21 mike Exp $
 
 // Z39.50 Exception classes
 
 #include <errno.h>
 #include <string.h>            // for strerror(), strlen(), strcpy()
 #include <stdio.h>             // for sprintf()
-#include <yaz/diagbib1.h>
-#include "zoom++.h"
+#include "zoom.h"
 
 
 namespace ZOOM {
@@ -14,11 +13,15 @@ namespace ZOOM {
        code = errcode;
     }
 
+    exception::~exception() {
+       // Nothing to do, but G++ requires this to be explicit anyway
+    }
+
     int exception::errcode() const {
        return code;
     }
 
-    const char *exception::errmsg() const {
+    string exception::errmsg() const {
        static char buf[40];
        sprintf(buf, "error #%d", code);
        return buf;
@@ -26,59 +29,50 @@ namespace ZOOM {
 
 
 
-    systemException::systemException() : exception::exception(errno){
+    systemException::systemException() : exception(errno){
        code = errno;
     }
 
-    int systemException::errcode() const {
-       return code;
-    }
-
-    const char *systemException::errmsg() const {
+    string systemException::errmsg() const {
        return strerror(code);
     }
 
 
-
-    bib1Exception::bib1Exception(int errcode, const char *addinfo) :
-       exception::exception(errcode) {
-       info = new char[strlen(addinfo)+1];
-       strcpy((char*) info, addinfo);
+    
+    bib1Exception::bib1Exception(int errcode, const string &addinfo) :
+       exception(errcode), info(addinfo) {
+       cerr << "WARNING: made bib1Exception(" << errcode << "=" <<
+           ZOOM_diag_str(errcode) << ", '" << addinfo << "')\n";
     }
 
     bib1Exception::~bib1Exception() {
-       delete info;
+       //fprintf(stderr, "deleting bib1Exception 0x%lx (%d, 0x%lx=%s)\n",
+               //(long) this, code, (long) info, info);
+       //delete info;
+       //  ### Don't actually do the deletion for now.  Exception
+       //  reference semantics are too weird for me to grok so I'm
+       //  doing The Wrong Thing in the knowledge that it will more
+       //  or less work -- it just leaks memory.  (Or does it?)
     }
 
-    int bib1Exception::errcode() const {
-       return code;
+    string bib1Exception::errmsg() const {
+       return ZOOM_diag_str(code);
     }
 
-    const char *bib1Exception::errmsg() const {
-       return diagbib1_str(code);
-    }
-
-    const char *bib1Exception::addinfo() const {
+    string bib1Exception::addinfo() const {
        return info;
     }
 
 
 
-    queryException::queryException(int qtype, const char *source) :
-       exception::exception(qtype) {
-       q = new char[strlen(source)+1];
-       strcpy((char*) q, source);
-    }
+    queryException::queryException(int qtype, const string &source) :
+       exception(qtype), q(source) {}
 
     queryException::~queryException() {
-       delete q;
-    }
-
-    int queryException::errcode() const {
-       return code;
+       //delete q; // ### see comment on bib1Exception destructor
     }
 
-    const char *queryException::errmsg() const {
+    string queryException::errmsg() const {
        switch (code) {
        case PREFIX: return "bad prefix search";
        case CCL: return "bad CCL search";
@@ -87,7 +81,7 @@ namespace ZOOM {
        return "bad search (unknown type)";
     }
 
-    const char *queryException::addinfo() const {
+    string queryException::addinfo() const {
        return q;
     }
 }