1 // Z39.50 Exception classes
5 #include <string.h> // for strerror(), strlen(), strcpy()
11 exception::exception(int errcode) {
15 exception::~exception() {
16 // Nothing to do, but G++ requires this to be explicit anyway
19 int exception::errcode() const {
23 std::string exception::errmsg() const {
25 sprintf(buf, "error #%d", code);
31 systemException::systemException() : exception(errno){
35 std::string systemException::errmsg() const {
36 // For thread safety on linux (and most unix systems), we need
37 // to use the reentrant version of the error translation
38 // function. Microsoft's strerror() is thread safe, since it
39 // returns a pointer to thread local storage. Unfortunately
40 // there several different reentrant versions. Here, we check
41 // for glibc, since we are using gcc. It appears at least the
42 // current version of gcc has strerror_r() available by
46 // PJD: result not necessarily equal to buf
47 const char* result = strerror_r(code, buf, sizeof(buf));
50 return exception::errmsg();
52 return strerror(code);
58 bib1Exception::bib1Exception(int errcode, const std::string &addinfo) :
59 exception(errcode), info(addinfo) {
60 // std::cerr << "WARNING: made bib1Exception(" << errcode << "=" <<
61 // ZOOM_diag_str(errcode) << ", '" << addinfo << "')\n";
64 bib1Exception::~bib1Exception() {
65 //fprintf(stderr, "deleting bib1Exception 0x%lx (%d, 0x%lx=%s)\n",
66 //(long) this, code, (long) info, info);
68 // ### Don't actually do the deletion for now. Exception
69 // reference semantics are too weird for me to grok so I'm
70 // doing The Wrong Thing in the knowledge that it will more
71 // or less work -- it just leaks memory. (Or does it?)
74 std::string bib1Exception::errmsg() const {
75 return ZOOM_diag_str(code);
78 std::string bib1Exception::addinfo() const {
84 queryException::queryException(int qtype, const std::string &source) :
85 exception(qtype), q(source) {}
87 queryException::~queryException() {
88 //delete q; // ### see comment on bib1Exception destructor
91 std::string queryException::errmsg() const {
93 case PREFIX: return "bad prefix search";
94 case CCL: return "bad CCL search";
97 return "bad search (unknown type)";
100 std::string queryException::addinfo() const {
107 * c-file-style: "Stroustrup"
108 * indent-tabs-mode: nil
110 * vim: shiftwidth=4 tabstop=8 expandtab