|
|
Index Data > YAZ++ > YAZ++ User's Guide and Reference > ZOOM::exception and subclasses
The
When any of the ZOOM methods fail, they respond by
The base class has this declaration:
class exception {
public:
exception (int code);
int errcode () const;
const char *errmsg () const;
};
It has three concrete subclasses:
class systemException: public exception {
public:
systemException ();
int errcode () const;
const char *errmsg () const;
};
Represents a ``system error'', typically indicating that a system
call failed - often in the low-level networking code that
underlies Z39.50.
class bib1Exception: public exception {
public:
bib1Exception (int errcode, const char *addinfo);
int errcode () const;
const char *errmsg () const;
const char *addinfo () const;
};
Represents an error condition communicated by a Z39.50 server.
For example, if a ZOOM application tries to search in the
``Voyager'' database of a server that does not have a database of
that name, a
class queryException: public exception {
public:
static const int PREFIX = 1;
static const int CCL = 2;
queryException (int qtype, const char *source);
int errcode () const;
const char *errmsg () const;
const char *addinfo () const;
};
This class represents an error in parsing a query into a form that
a Z39.50 can understand. It must be created with the
Now we can revise the sample program from the introduction to catch exceptions and report any errors:
/* g++ -o zoom-c++-hw zoom-c++-hw.cpp -lzoompp -lyaz */
#include <iostream>
#include <yazpp/zoom.h>
using namespace ZOOM;
int main(int argc, char **argv)
{
try {
connection conn("z3950.loc.gov", 7090);
conn.option("databaseName", "Voyager");
conn.option("preferredRecordSyntax", "USMARC");
resultSet rs(conn, prefixQuery("@attr 1=7 0253333490"));
const record *rec = rs.getRecord(0);
cout << rec->render() << endl;
} catch (systemException &e) {
cerr << "System error " <<
e.errcode() << " (" << e.errmsg() << ")" << endl;
} catch (bib1Exception &e) {
cerr << "BIB-1 error " <<
e.errcode() << " (" << e.errmsg() << "): " << e.addinfo() << endl;
} catch (queryException &e) {
cerr << "Query error " <<
e.errcode() << " (" << e.errmsg() << "): " << e.addinfo() << endl;
} catch (exception &e) {
cerr << "Error " <<
e.errcode() << " (" << e.errmsg() << ")" << endl;
}
}
The heart of this program is the same as in the original version,
but it's now wrapped in a
The first such block diagnoses system-level errors such as memory
exhaustion or a network connection being broken by a server's
untimely death; the second catches errors at the Z39.50 level,
such as a server's report that it can't provide records in USMARC
syntax; the third is there in case there's something wrong with
the syntax of the query (although in this case it's correct); and
finally, the last
Because C does not support exceptions, ZOOM-C has no API element
that corresponds directly with ZOOM-C++'s
|
|||
|
|
||||
| Copyright Index Data ApS 2008 | ||||