1 // $Header: /home/cvsroot/yaz++/zoom/zexcept.cpp,v 1.11 2005-06-25 15:53:21 adam Exp $
3 // Z39.50 Exception classes
7 #include <string.h> // for strerror(), strlen(), strcpy()
13 exception::exception(int errcode) {
17 exception::~exception() {
18 // Nothing to do, but G++ requires this to be explicit anyway
21 int exception::errcode() const {
25 std::string exception::errmsg() const {
27 sprintf(buf, "error #%d", code);
33 systemException::systemException() : exception(errno){
37 std::string systemException::errmsg() const {
38 // For thread safety on linux (and most unix systems), we need
39 // to use the reentrant version of the error translation
40 // function. Microsoft's strerror() is thread safe, since it
41 // returns a pointer to thread local storage. Unfortunately
42 // there several different reentrant versions. Here, we check
43 // for glibc, since we are using gcc. It appears at least the
44 // current version of gcc has strerror_r() available by
48 // PJD: result not necessarily equal to buf
49 const char* result = strerror_r(code, buf, sizeof(buf));
52 return exception::errmsg();
54 return strerror(code);
60 bib1Exception::bib1Exception(int errcode, const std::string &addinfo) :
61 exception(errcode), info(addinfo) {
62 // std::cerr << "WARNING: made bib1Exception(" << errcode << "=" <<
63 // ZOOM_diag_str(errcode) << ", '" << addinfo << "')\n";
66 bib1Exception::~bib1Exception() {
67 //fprintf(stderr, "deleting bib1Exception 0x%lx (%d, 0x%lx=%s)\n",
68 //(long) this, code, (long) info, info);
70 // ### Don't actually do the deletion for now. Exception
71 // reference semantics are too weird for me to grok so I'm
72 // doing The Wrong Thing in the knowledge that it will more
73 // or less work -- it just leaks memory. (Or does it?)
76 std::string bib1Exception::errmsg() const {
77 return ZOOM_diag_str(code);
80 std::string bib1Exception::addinfo() const {
86 queryException::queryException(int qtype, const std::string &source) :
87 exception(qtype), q(source) {}
89 queryException::~queryException() {
90 //delete q; // ### see comment on bib1Exception destructor
93 std::string queryException::errmsg() const {
95 case PREFIX: return "bad prefix search";
96 case CCL: return "bad CCL search";
99 return "bad search (unknown type)";
102 std::string queryException::addinfo() const {
109 * indent-tabs-mode: nil
111 * vim: shiftwidth=4 tabstop=8 expandtab