From ea733d0f5dcdee6278e22866c95aa2f706793852 Mon Sep 17 00:00:00 2001 From: mike Date: Wed, 12 Oct 2005 13:44:05 +0000 Subject: [PATCH] Exception-handling. --- samples/zoom/zoomtst1.pl | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/samples/zoom/zoomtst1.pl b/samples/zoom/zoomtst1.pl index 5e05f54..a1a1ffd 100644 --- a/samples/zoom/zoomtst1.pl +++ b/samples/zoom/zoomtst1.pl @@ -1,4 +1,4 @@ -# $Id: zoomtst1.pl,v 1.1 2005-10-12 11:53:27 mike Exp $ +# $Id: zoomtst1.pl,v 1.2 2005-10-12 13:44:05 mike Exp $ # # See ../README for a description of this program. # perl -I../../blib/lib -I../../blib/arch zoomtst1.pl @@ -12,17 +12,25 @@ if (@ARGV != 2) { print STDERR " eg. $0 bagel.indexdata.dk/gils computer\n"; exit 1; } - my($host, $query) = @ARGV; -my $conn = new ZOOM::Connection($host, 0); -$conn->option(preferredRecordSyntax => "usmarc"); -my $rs = $conn->search_pqf($query); -my $n = $rs->size(); -for my $i (0..$n-1) { - my $rec = $rs->record($i); - print "=== Record ", $i+1, " of $n ===\n"; - print $rec->render(); -} -$rs->destroy(); -$conn->destroy(); +eval { + my $conn = new ZOOM::Connection($host, 0); + $conn->option(preferredRecordSyntax => "usmarc"); + my $rs = $conn->search_pqf($query); + my $n = $rs->size(); + for my $i (0..$n-1) { + my $rec = $rs->record($i); + print "=== Record ", $i+1, " of $n ===\n"; + print $rec->render(); + } + + $rs->destroy(); + $conn->destroy(); +}; if ($@) { + die "Non-ZOOM error: $@" if !$@->isa("ZOOM::Exception"); + print STDERR "Error ", $@->code(), ": ", $@->message(); + print STDERR " (", $@->addinfo(), ")" if $@->addinfo(); + print STDERR "\n"; + exit 1; +} -- 1.7.10.4