1 // $Header: /home/cvsroot/yaz++/zoom/zexcept.cpp,v 1.3 2002-10-09 09:07:10 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::exception(errno){
33 int systemException::errcode() const {
37 const char *systemException::errmsg() const {
38 return strerror(code);
43 bib1Exception::bib1Exception(int errcode, const char *addinfo) :
44 exception::exception(errcode) {
45 info = new char[strlen(addinfo)+1];
46 strcpy((char*) info, addinfo);
47 //fprintf(stderr, "made new bib1Exception 0x%lx (%d, 0x%lx=%s)\n",
48 //(long) this, code, (long) info, info);
52 bib1Exception::bib1Exception(bib1Exception& src) :
53 exception::exception(src) {
55 info = new char[strlen(src.info)+1];
56 strcpy((char*) info, src.info);
57 //fprintf(stderr, "copied bib1Exception 0x%lx to 0x%lx (%d, 0x%lx=%s)\n",
58 //(long) &src, (long) this, code, (long) info, info);
62 bib1Exception::~bib1Exception() {
63 //fprintf(stderr, "deleting bib1Exception 0x%lx (%d, 0x%lx=%s)\n",
64 //(long) this, code, (long) info, info);
66 // ### Don't actually do the deletion for now. Exception
67 // reference semantics are too weird for me to grok so I'm
68 // doing The Wrong Thing in the knowledge that it will more
69 // or less work -- it just leaks memory.
72 int bib1Exception::errcode() const {
76 const char *bib1Exception::errmsg() const {
77 return diagbib1_str(code);
80 const char *bib1Exception::addinfo() const {
86 queryException::queryException(int qtype, const char *source) :
87 exception::exception(qtype) {
88 q = new char[strlen(source)+1];
89 strcpy((char*) q, source);
92 queryException::~queryException() {
96 int queryException::errcode() const {
100 const char *queryException::errmsg() const {
102 case PREFIX: return "bad prefix search";
103 case CCL: return "bad CCL search";
106 return "bad search (unknown type)";
109 const char *queryException::addinfo() const {