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