Remove vacuous redeclarations and redefinitions of the errcode()
[yazpp-moved-to-github.git] / zoom / zexcept.cpp
1 // $Header: /home/cvsroot/yaz++/zoom/zexcept.cpp,v 1.6 2002-11-12 22:43:56 mike Exp $
2
3 // Z39.50 Exception classes
4
5 #include <errno.h>
6 #include <string.h>             // for strerror(), strlen(), strcpy()
7 #include <stdio.h>              // for sprintf()
8 #include <yaz/diagbib1.h>
9 #include "zoom.h"
10
11
12 namespace ZOOM {
13     exception::exception(int errcode) {
14         code = errcode;
15     }
16
17     int exception::errcode() const {
18         return code;
19     }
20
21     const char *exception::errmsg() const {
22         static char buf[40];
23         sprintf(buf, "error #%d", code);
24         return buf;
25     }
26
27
28
29     systemException::systemException() : exception(errno){
30         code = errno;
31     }
32
33     const char *systemException::errmsg() const {
34         return strerror(code);
35     }
36
37
38     
39     bib1Exception::bib1Exception(int errcode, const char *addinfo) :
40         exception(errcode) {
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);
45     }
46
47 #if 0
48     bib1Exception::bib1Exception(bib1Exception& src) :
49         exception(src) {
50         code = src.code;
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);
55     }
56 #endif
57
58     bib1Exception::~bib1Exception() {
59         //fprintf(stderr, "deleting bib1Exception 0x%lx (%d, 0x%lx=%s)\n",
60                 //(long) this, code, (long) info, info);
61         //delete 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.
66     }
67
68     const char *bib1Exception::errmsg() const {
69         return diagbib1_str(code);
70     }
71
72     const char *bib1Exception::addinfo() const {
73         return info;
74     }
75
76
77
78     queryException::queryException(int qtype, const char *source) :
79         exception(qtype) {
80         q = new char[strlen(source)+1];
81         strcpy((char*) q, source);
82     }
83
84     queryException::~queryException() {
85         //delete q; // ### see comment on bib1Exception destructor
86     }
87
88     const char *queryException::errmsg() const {
89         switch (code) {
90         case PREFIX: return "bad prefix search";
91         case CCL: return "bad CCL search";
92         default: break;
93         }
94         return "bad search (unknown type)";
95     }
96
97     const char *queryException::addinfo() const {
98         return q;
99     }
100 }