From: Mike Taylor Date: Thu, 8 Aug 2002 16:06:08 +0000 (+0000) Subject: Rename error classes to exception. Rename zerr.cpp X-Git-Tag: YAZPP.0.3~12 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=7c6295779d21f882f9d53186c5a751cbf86b6c86;p=yazpp-moved-to-github.git Rename error classes to exception. Rename zerr.cpp --- diff --git a/zoom/Changes b/zoom/Changes index 266869a..e8e0549 100644 --- a/zoom/Changes +++ b/zoom/Changes @@ -7,7 +7,7 @@ expect to become version 1.3a of the official specification.) Add #include for size_t -Add comment about G++'s rejection of throw(ZOOM:error) clause +Add comment about G++'s rejection of throw(ZOOM:exception) clause Add destructor declaration to connection class. @@ -26,13 +26,17 @@ version 1.3 of the ZOOM AAPI. Remove the nfields() and field() methods from the record class -- again, see v1.3 of the AAPI. -Add some substance to the error base class: it can now be created +Rename the error class to exception, and its subclasses likewise. I +think that's Telling It Like It Is, and it's certainly more in tune +with the was v1.3 of the AAPI is going. + +Add some substance to the exception base class: it can now be created (with an error-code specified), and the error-code may be both fetched and rendered as a human-readable string. This is necessary so that -it's possible to meaningfully catch(error e). +it's possible to meaningfully catch(exception e). -Add the missing char *errmsg() method to the systemError and bib1Error -classes. +Add the missing char *errmsg() method to the systemException and +bib1Exception classes. -Add a new error subclass, queryError, for reporting malformed query -strings etc. +Add a new exception subclass, queryException, for reporting malformed +query strings etc. diff --git a/zoom/master-header b/zoom/master-header index c573e33..a66b089 100644 --- a/zoom/master-header +++ b/zoom/master-header @@ -1,4 +1,4 @@ -// $Header: /home/cvsroot/yaz++/zoom/master-header,v 1.1 2002-08-08 13:31:54 mike Exp $ +// $Header: /home/cvsroot/yaz++/zoom/master-header,v 1.2 2002-08-08 16:06:08 mike Exp $ // // ZOOM C++ Binding. // The ZOOM homepage is at http://zoom.z3950.org/ @@ -34,12 +34,12 @@ namespace ZOOM { * ZOOM_connection c; public: connection (const char *hostname, int portnum); - // ### I would like to add a ``throw (ZOOM::error)'' clause + // ### I would like to add a ``throw (ZOOM::exception)'' clause // here, but it looks like G++ 2.95.2 doesn't recognise it. ~connection (); const char *option (const char *key) const; const char *option (const char *key, const char *val); -* ZOOM_connection _getYazConnection() const { return c; } // package-private +* ZOOM_connection _getYazConnection () const { return c; } // package-private }; class query { @@ -48,19 +48,19 @@ namespace ZOOM { * ZOOM_query q; public: virtual ~query (); -* ZOOM_query _getYazQuery() const { return q; } // package-private +* ZOOM_query _getYazQuery () const { return q; } // package-private }; class prefixQuery : public query { public: prefixQuery (const char *pqn); - ~prefixQuery(); + ~prefixQuery (); }; class CCLQuery : public query { public: CCLQuery (const char *ccl, void *qualset); - ~CCLQuery(); + ~CCLQuery (); }; class resultSet { @@ -79,8 +79,8 @@ namespace ZOOM { * const resultSet *owner; * ZOOM_record r; public: -* record::record(const resultSet *rs, ZOOM_record rec): -* owner(rs), r(rec) {} +* record::record (const resultSet *rs, ZOOM_record rec): +* owner (rs), r (rec) {} ~record (); enum syntax { UNKNOWN, GRS1, SUTRS, USMARC, UKMARC, XML @@ -91,39 +91,39 @@ namespace ZOOM { const char *rawdata () const; }; - class error { + class exception { * protected: * int code; public: - error (int code); + exception (int code); int errcode () const; const char *errmsg () const; }; - class systemError: public error { + class systemException: public exception { public: - systemError (); + systemException (); int errcode () const; const char *errmsg () const; }; - class bib1Error: public error { + class bib1Exception: public exception { * const char *info; public: -* ~bib1Error(); - bib1Error (int errcode, const char *addinfo); +* ~bib1Exception (); + bib1Exception (int errcode, const char *addinfo); int errcode () const; const char *errmsg () const; const char *addinfo () const; }; - class queryError: public error { + class queryException: public exception { * const char *q; public: -* ~queryError(); +* ~queryException (); static const int PREFIX = 1; static const int CCL = 2; - queryError (int qtype, const char *source); + queryException (int qtype, const char *source); int errcode () const; const char *errmsg () const; const char *addinfo () const; diff --git a/zoom/zclient.cpp b/zoom/zclient.cpp index 8a1bb95..863968d 100644 --- a/zoom/zclient.cpp +++ b/zoom/zclient.cpp @@ -1,4 +1,4 @@ -// $Header: /home/cvsroot/yaz++/zoom/zclient.cpp,v 1.1 2002-08-08 13:31:54 mike Exp $ +// $Header: /home/cvsroot/yaz++/zoom/zclient.cpp,v 1.2 2002-08-08 16:06:08 mike Exp $ // Trivial sample client @@ -22,12 +22,13 @@ int main(int argc, char **argv) ZOOM::connection *conn; try { conn = new ZOOM::connection(hostname, port); - } catch(ZOOM::bib1Error err) { - cerr << argv[0] << ": connect: " << + } catch(ZOOM::bib1Exception err) { + cerr << argv[0] << ": connect: bib1Exception " << err.errmsg() << " (" << err.addinfo() << ")\n"; return 2; - } catch(ZOOM::error err) { - cerr << argv[0] << ": connect: " << err.errmsg() << "\n"; + } catch(ZOOM::exception err) { + cerr << argv[0] << ": connect: exception " << + err.errmsg() << "\n"; return 2; } @@ -36,7 +37,7 @@ int main(int argc, char **argv) ZOOM::resultSet *rs; try { rs = new ZOOM::resultSet(*conn, pq); - } catch(ZOOM::bib1Error err) { + } catch(ZOOM::bib1Exception err) { cerr << argv[0] << ": searchSpec: " << err.errmsg() << " (" << err.addinfo() << ")\n"; return 3; diff --git a/zoom/zconn.cpp b/zoom/zconn.cpp index e6f9dc9..8aad4ab 100644 --- a/zoom/zconn.cpp +++ b/zoom/zconn.cpp @@ -1,4 +1,4 @@ -// $Header: /home/cvsroot/yaz++/zoom/zconn.cpp,v 1.1 2002-08-08 13:31:54 mike Exp $ +// $Header: /home/cvsroot/yaz++/zoom/zconn.cpp,v 1.2 2002-08-08 16:06:08 mike Exp $ // Z39.50 Connection class @@ -13,7 +13,7 @@ namespace ZOOM { const char *errmsg; // unused: carries same info as `errcode' const char *addinfo; if ((errcode = ZOOM_connection_error(c, &errmsg, &addinfo)) != 0) { - throw bib1Error(errcode, addinfo); + throw bib1Exception(errcode, addinfo); } } diff --git a/zoom/zerr.cpp b/zoom/zerr.cpp deleted file mode 100644 index e418003..0000000 --- a/zoom/zerr.cpp +++ /dev/null @@ -1,93 +0,0 @@ -// $Header: /home/cvsroot/yaz++/zoom/Attic/zerr.cpp,v 1.1 2002-08-08 13:31:54 mike Exp $ - -// Z39.50 Error classes - -#include -#include // for strerror(), strlen(), strcpy() -#include // for sprintf() -#include -#include "zoom++.h" - - -namespace ZOOM { - error::error(int errcode) { - code = errcode; - } - - int error::errcode() const { - return code; - } - - const char *error::errmsg() const { - static char buf[40]; - sprintf(buf, "error #%d", code); - return buf; - } - - - - systemError::systemError() : error::error(errno){ - code = errno; - } - - int systemError::errcode() const { - return code; - } - - const char *systemError::errmsg() const { - return strerror(code); - } - - - - bib1Error::bib1Error(int errcode, const char *addinfo) : - error::error(errcode) { - info = new char[strlen(addinfo)+1]; - strcpy((char*) info, addinfo); - } - - bib1Error::~bib1Error() { - delete info; - } - - int bib1Error::errcode() const { - return code; - } - - const char *bib1Error::errmsg() const { - return diagbib1_str(code); - } - - const char *bib1Error::addinfo() const { - return info; - } - - - - queryError::queryError(int qtype, const char *source) : - error::error(qtype) { - q = new char[strlen(source)+1]; - strcpy((char*) q, source); - } - - queryError::~queryError() { - delete q; - } - - int queryError::errcode() const { - return code; - } - - const char *queryError::errmsg() const { - switch (code) { - case PREFIX: return "bad prefix search"; - case CCL: return "bad CCL search"; - default: break; - } - return "bad search (unknown type)"; - } - - const char *queryError::addinfo() const { - return q; - } -} diff --git a/zoom/zexcept.cpp b/zoom/zexcept.cpp new file mode 100644 index 0000000..7113a4d --- /dev/null +++ b/zoom/zexcept.cpp @@ -0,0 +1,93 @@ +// $Header: /home/cvsroot/yaz++/zoom/zexcept.cpp,v 1.1 2002-08-08 16:06:08 mike Exp $ + +// Z39.50 Exception classes + +#include +#include // for strerror(), strlen(), strcpy() +#include // for sprintf() +#include +#include "zoom++.h" + + +namespace ZOOM { + exception::exception(int errcode) { + code = errcode; + } + + int exception::errcode() const { + return code; + } + + const char *exception::errmsg() const { + static char buf[40]; + sprintf(buf, "error #%d", code); + return buf; + } + + + + systemException::systemException() : exception::exception(errno){ + code = errno; + } + + int systemException::errcode() const { + return code; + } + + const char *systemException::errmsg() const { + return strerror(code); + } + + + + bib1Exception::bib1Exception(int errcode, const char *addinfo) : + exception::exception(errcode) { + info = new char[strlen(addinfo)+1]; + strcpy((char*) info, addinfo); + } + + bib1Exception::~bib1Exception() { + delete info; + } + + int bib1Exception::errcode() const { + return code; + } + + const char *bib1Exception::errmsg() const { + return diagbib1_str(code); + } + + const char *bib1Exception::addinfo() const { + return info; + } + + + + queryException::queryException(int qtype, const char *source) : + exception::exception(qtype) { + q = new char[strlen(source)+1]; + strcpy((char*) q, source); + } + + queryException::~queryException() { + delete q; + } + + int queryException::errcode() const { + return code; + } + + const char *queryException::errmsg() const { + switch (code) { + case PREFIX: return "bad prefix search"; + case CCL: return "bad CCL search"; + default: break; + } + return "bad search (unknown type)"; + } + + const char *queryException::addinfo() const { + return q; + } +} diff --git a/zoom/zquery.cpp b/zoom/zquery.cpp index 77c0d93..602663f 100644 --- a/zoom/zquery.cpp +++ b/zoom/zquery.cpp @@ -1,4 +1,4 @@ -// $Header: /home/cvsroot/yaz++/zoom/zquery.cpp,v 1.1 2002-08-08 13:31:54 mike Exp $ +// $Header: /home/cvsroot/yaz++/zoom/zquery.cpp,v 1.2 2002-08-08 16:06:08 mike Exp $ // Z39.50 Query classes @@ -17,7 +17,7 @@ namespace ZOOM { q = ZOOM_query_create(); if (ZOOM_query_prefix(q, pqn) == -1) { ZOOM_query_destroy(q); - throw queryError(queryError::PREFIX, pqn); + throw queryException(queryException::PREFIX, pqn); } } diff --git a/zoom/zrec.cpp b/zoom/zrec.cpp index 18e34be..2a0bd6f 100644 --- a/zoom/zrec.cpp +++ b/zoom/zrec.cpp @@ -1,4 +1,4 @@ -// $Header: /home/cvsroot/yaz++/zoom/zrec.cpp,v 1.1 2002-08-08 13:31:54 mike Exp $ +// $Header: /home/cvsroot/yaz++/zoom/zrec.cpp,v 1.2 2002-08-08 16:06:08 mike Exp $ // Z39.50 Record class @@ -23,7 +23,7 @@ namespace ZOOM { record *rec = new record(0, 0); if ((rec->r = ZOOM_record_clone(r)) == 0) { // Presumably an out-of-memory error - throw systemError(); + throw systemException(); } return rec; diff --git a/zoom/zrs.cpp b/zoom/zrs.cpp index 39d0422..48e212c 100644 --- a/zoom/zrs.cpp +++ b/zoom/zrs.cpp @@ -1,4 +1,4 @@ -// $Header: /home/cvsroot/yaz++/zoom/zrs.cpp,v 1.1 2002-08-08 13:31:54 mike Exp $ +// $Header: /home/cvsroot/yaz++/zoom/zrs.cpp,v 1.2 2002-08-08 16:06:08 mike Exp $ // Z39.50 Result Set class @@ -14,7 +14,7 @@ namespace ZOOM { const char *addinfo; if ((errcode = ZOOM_connection_error(yazc, &errmsg, &addinfo)) != 0) { - throw bib1Error(errcode, addinfo); + throw bib1Exception(errcode, addinfo); } } @@ -44,7 +44,7 @@ namespace ZOOM { const char *addinfo; int errcode = ZOOM_connection_error(owner._getYazConnection(), &errmsg, &addinfo); - throw bib1Error(errcode, addinfo); + throw bib1Exception(errcode, addinfo); } // Memory management is odd here. The ZOOM-C record we've