X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=zoom%2Fzexcept.cpp;h=3a11382ae5cb6812c82996183c21119777bdf3f2;hb=6807f0e768d9578ceefca99fd1b59d98a9d4005a;hp=a012c5d79435ad4d8a6733daa51682cf8dff246e;hpb=c29b07cd7dc9cd6945bf79477e0ccd10252485bf;p=yazpp-moved-to-github.git diff --git a/zoom/zexcept.cpp b/zoom/zexcept.cpp index a012c5d..3a11382 100644 --- a/zoom/zexcept.cpp +++ b/zoom/zexcept.cpp @@ -1,11 +1,11 @@ -// $Header: /home/cvsroot/yaz++/zoom/zexcept.cpp,v 1.5 2002-10-30 09:13:12 adam Exp $ +// $Header: /home/cvsroot/yaz++/zoom/zexcept.cpp,v 1.9 2003-07-07 09:23:16 adam Exp $ // Z39.50 Exception classes +#include #include #include // for strerror(), strlen(), strcpy() -#include // for sprintf() -#include +#include #include "zoom.h" @@ -14,11 +14,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; @@ -30,34 +34,17 @@ namespace ZOOM { 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(errcode) { - info = new char[strlen(addinfo)+1]; - strcpy((char*) info, addinfo); - //fprintf(stderr, "made new bib1Exception 0x%lx (%d, 0x%lx=%s)\n", - //(long) this, code, (long) info, info); - } - -#if 0 - bib1Exception::bib1Exception(bib1Exception& src) : - exception(src) { - code = src.code; - info = new char[strlen(src.info)+1]; - strcpy((char*) info, src.info); - //fprintf(stderr, "copied bib1Exception 0x%lx to 0x%lx (%d, 0x%lx=%s)\n", - //(long) &src, (long) this, code, (long) info, info); + bib1Exception::bib1Exception(int errcode, const std::string &addinfo) : + exception(errcode), info(addinfo) { + std::cerr << "WARNING: made bib1Exception(" << errcode << "=" << + ZOOM_diag_str(errcode) << ", '" << addinfo << "')\n"; } -#endif bib1Exception::~bib1Exception() { //fprintf(stderr, "deleting bib1Exception 0x%lx (%d, 0x%lx=%s)\n", @@ -66,38 +53,27 @@ namespace ZOOM { // ### 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 less work -- it just leaks memory. (Or does it?) } - int bib1Exception::errcode() const { - return code; - } - - const char *bib1Exception::errmsg() const { - return diagbib1_str(code); + std::string bib1Exception::errmsg() const { + return ZOOM_diag_str(code); } - const char *bib1Exception::addinfo() const { + std::string bib1Exception::addinfo() const { return info; } - queryException::queryException(int qtype, const char *source) : - 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; // ### see comment on bib1Exception destructor } - int queryException::errcode() const { - return code; - } - - const char *queryException::errmsg() const { + std::string queryException::errmsg() const { switch (code) { case PREFIX: return "bad prefix search"; case CCL: return "bad CCL search"; @@ -106,7 +82,7 @@ namespace ZOOM { return "bad search (unknown type)"; } - const char *queryException::addinfo() const { + std::string queryException::addinfo() const { return q; } }