X-Git-Url: http://git.indexdata.com/?p=yazpp-moved-to-github.git;a=blobdiff_plain;f=zoom%2Fzexcept.cpp;h=04e666554fa729868e1699a5afe8c9553bd2dbf4;hp=cef62979afe358891493a6ec3c7bdd41eaa46f9e;hb=3293084bd0b889ce7a3a87517f40e985ad2eb7ef;hpb=9e4ee094248d1c5a0fdb5b80ac86c290a36f7056 diff --git a/zoom/zexcept.cpp b/zoom/zexcept.cpp index cef6297..04e6665 100644 --- a/zoom/zexcept.cpp +++ b/zoom/zexcept.cpp @@ -1,11 +1,10 @@ -// $Header: /home/cvsroot/yaz++/zoom/zexcept.cpp,v 1.6 2002-11-12 22:43:56 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 #include // for strerror(), strlen(), strcpy() #include // for sprintf() -#include #include "zoom.h" @@ -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; @@ -30,31 +33,18 @@ namespace ZOOM { code = errno; } - const char *systemException::errmsg() const { + 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); + bib1Exception::bib1Exception(int errcode, const string &addinfo) : + exception(errcode), info(addinfo) { + cerr << "WARNING: made bib1Exception(" << errcode << "=" << + ZOOM_diag_str(errcode) << ", '" << addinfo << "')\n"; } -#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); - } -#endif - bib1Exception::~bib1Exception() { //fprintf(stderr, "deleting bib1Exception 0x%lx (%d, 0x%lx=%s)\n", //(long) this, code, (long) info, info); @@ -62,30 +52,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?) } - const char *bib1Exception::errmsg() const { - return diagbib1_str(code); + string bib1Exception::errmsg() const { + return ZOOM_diag_str(code); } - const char *bib1Exception::addinfo() const { + 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 string &source) : + exception(qtype), q(source) {} queryException::~queryException() { //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"; @@ -94,7 +81,7 @@ namespace ZOOM { return "bad search (unknown type)"; } - const char *queryException::addinfo() const { + string queryException::addinfo() const { return q; } }