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