Bash the implementation into the same shape as the interface,
[yazpp-moved-to-github.git] / zoom / zexcept.cpp
1 // $Header: /home/cvsroot/yaz++/zoom/zexcept.cpp,v 1.7 2002-11-30 22:33:21 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 "zoom.h"
9
10
11 namespace ZOOM {
12     exception::exception(int errcode) {
13         code = errcode;
14     }
15
16     exception::~exception() {
17         // Nothing to do, but G++ requires this to be explicit anyway
18     }
19
20     int exception::errcode() const {
21         return code;
22     }
23
24     string exception::errmsg() const {
25         static char buf[40];
26         sprintf(buf, "error #%d", code);
27         return buf;
28     }
29
30
31
32     systemException::systemException() : exception(errno){
33         code = errno;
34     }
35
36     string systemException::errmsg() const {
37         return strerror(code);
38     }
39
40
41     
42     bib1Exception::bib1Exception(int errcode, const string &addinfo) :
43         exception(errcode), info(addinfo) {
44         cerr << "WARNING: made bib1Exception(" << errcode << "=" <<
45             ZOOM_diag_str(errcode) << ", '" << addinfo << "')\n";
46     }
47
48     bib1Exception::~bib1Exception() {
49         //fprintf(stderr, "deleting bib1Exception 0x%lx (%d, 0x%lx=%s)\n",
50                 //(long) this, code, (long) info, info);
51         //delete info;
52         //  ### Don't actually do the deletion for now.  Exception
53         //  reference semantics are too weird for me to grok so I'm
54         //  doing The Wrong Thing in the knowledge that it will more
55         //  or less work -- it just leaks memory.  (Or does it?)
56     }
57
58     string bib1Exception::errmsg() const {
59         return ZOOM_diag_str(code);
60     }
61
62     string bib1Exception::addinfo() const {
63         return info;
64     }
65
66
67
68     queryException::queryException(int qtype, const string &source) :
69         exception(qtype), q(source) {}
70
71     queryException::~queryException() {
72         //delete q; // ### see comment on bib1Exception destructor
73     }
74
75     string queryException::errmsg() const {
76         switch (code) {
77         case PREFIX: return "bad prefix search";
78         case CCL: return "bad CCL search";
79         default: break;
80         }
81         return "bad search (unknown type)";
82     }
83
84     string queryException::addinfo() const {
85         return q;
86     }
87 }