1 // $Header: /home/cvsroot/yaz++/zoom/zexcept.cpp,v 1.6 2002-11-12 22:43:56 mike Exp $
3 // Z39.50 Exception classes
6 #include <string.h> // for strerror(), strlen(), strcpy()
7 #include <stdio.h> // for sprintf()
8 #include <yaz/diagbib1.h>
13 exception::exception(int errcode) {
17 int exception::errcode() const {
21 const char *exception::errmsg() const {
23 sprintf(buf, "error #%d", code);
29 systemException::systemException() : exception(errno){
33 const char *systemException::errmsg() const {
34 return strerror(code);
39 bib1Exception::bib1Exception(int errcode, const char *addinfo) :
41 info = new char[strlen(addinfo)+1];
42 strcpy((char*) info, addinfo);
43 //fprintf(stderr, "made new bib1Exception 0x%lx (%d, 0x%lx=%s)\n",
44 //(long) this, code, (long) info, info);
48 bib1Exception::bib1Exception(bib1Exception& src) :
51 info = new char[strlen(src.info)+1];
52 strcpy((char*) info, src.info);
53 //fprintf(stderr, "copied bib1Exception 0x%lx to 0x%lx (%d, 0x%lx=%s)\n",
54 //(long) &src, (long) this, code, (long) info, info);
58 bib1Exception::~bib1Exception() {
59 //fprintf(stderr, "deleting bib1Exception 0x%lx (%d, 0x%lx=%s)\n",
60 //(long) this, code, (long) info, info);
62 // ### Don't actually do the deletion for now. Exception
63 // reference semantics are too weird for me to grok so I'm
64 // doing The Wrong Thing in the knowledge that it will more
65 // or less work -- it just leaks memory.
68 const char *bib1Exception::errmsg() const {
69 return diagbib1_str(code);
72 const char *bib1Exception::addinfo() const {
78 queryException::queryException(int qtype, const char *source) :
80 q = new char[strlen(source)+1];
81 strcpy((char*) q, source);
84 queryException::~queryException() {
85 //delete q; // ### see comment on bib1Exception destructor
88 const char *queryException::errmsg() const {
90 case PREFIX: return "bad prefix search";
91 case CCL: return "bad CCL search";
94 return "bad search (unknown type)";
97 const char *queryException::addinfo() const {