X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=zoom%2Fzexcept.cpp;h=462767bd4a7c248217a09c117620917dad566a76;hb=01126607d1b475f43b29548dbd98f199f8e9f57f;hp=7113a4d014c5dd71c60d5c2089d0c416bd061ed4;hpb=7c6295779d21f882f9d53186c5a751cbf86b6c86;p=yazpp-moved-to-github.git diff --git a/zoom/zexcept.cpp b/zoom/zexcept.cpp index 7113a4d..462767b 100644 --- a/zoom/zexcept.cpp +++ b/zoom/zexcept.cpp @@ -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.8 2003-07-02 10:25:13 adam Exp $ // Z39.50 Exception classes +#include #include #include // for strerror(), strlen(), strcpy() -#include // for sprintf() -#include -#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 { + std::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 { + std::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 std::string &addinfo) : + exception(errcode), info(addinfo) { + std::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; + std::string bib1Exception::errmsg() const { + return ZOOM_diag_str(code); } - const char *bib1Exception::errmsg() const { - return diagbib1_str(code); - } - - const char *bib1Exception::addinfo() const { + std::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 std::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 { + std::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 { + std::string queryException::addinfo() const { return q; } }