Add Makefile.in to .cvsignore
[yazpp-moved-to-github.git] / zoom / zexcept.cpp
1 // $Header: /home/cvsroot/yaz++/zoom/zexcept.cpp,v 1.1 2002-08-08 16:06:08 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::exception(errno){
30         code = errno;
31     }
32
33     int systemException::errcode() const {
34         return code;
35     }
36
37     const char *systemException::errmsg() const {
38         return strerror(code);
39     }
40
41
42
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     }
48
49     bib1Exception::~bib1Exception() {
50         delete info;
51     }
52
53     int bib1Exception::errcode() const {
54         return code;
55     }
56
57     const char *bib1Exception::errmsg() const {
58         return diagbib1_str(code);
59     }
60
61     const char *bib1Exception::addinfo() const {
62         return info;
63     }
64
65
66
67     queryException::queryException(int qtype, const char *source) :
68         exception::exception(qtype) {
69         q = new char[strlen(source)+1];
70         strcpy((char*) q, source);
71     }
72
73     queryException::~queryException() {
74         delete q;
75     }
76
77     int queryException::errcode() const {
78         return code;
79     }
80
81     const char *queryException::errmsg() const {
82         switch (code) {
83         case PREFIX: return "bad prefix search";
84         case CCL: return "bad CCL search";
85         default: break;
86         }
87         return "bad search (unknown type)";
88     }
89
90     const char *queryException::addinfo() const {
91         return q;
92     }
93 }