[Bioperl-l] handling errors?

Stephen Henderson s.henderson@ucl.ac.uk
Tue, 22 May 2001 16:43:20 +0100


I am having trouble handling run-time errors in my code.

Simply I am trying to go through a batch of accession no. and connect to
Genbank to download sequences and write them to a file.
But I only get so far before I get some sort of connection or unrecognised
error I have tried using eval to handle this but the program just dies
instead of continuing. 

Here is the code

open (ACCS, "C:\\Perl\\BioPerl-0.7\\Seqdata\\Accessionlist.txt") or die
"can't open Accessions file";
$seqout = Bio::SeqIO->new( '-format' => 'Fasta', -file =>"+>DNAout")or die
"can't open DNAoutput file";

@ets=<ACCS>;
$ets_count=@ets;
$gb= new Bio::DB::GenBank();

        for($i=0; $i < $ets_count; $i++)
        {
                eval
                {
                        $seq = $gb->get_Seq_by_id($ets[$i]);
                        $detail= $seq->display_id();
                        print $detail, "\n";
                };

The errors are not however caught and instead I get

"Can't call method "display_id" on an undefined value at NCBI.pl line 22"
and
"Can't call method "seq" on an undefined value at Bio/SeqIO/fasta.pm line
166"

Does anyone see the problem with using eval here?