Howdy,

If I'm handling errors with
eval {} if ($@) {}
constructs, is there any hidden gotcha to grouping several statements in a 
single eval if I want any errors handled identically?  For instance, can I wrap 
an execute and its fetches into one eval, as below, or is this something I 
should be wary of?

Paul

# group an execute and its fetches into one eval
eval {
    $sth->execute();
    while (my $ref = $sth->fetchrow_arrayref()) {
          print OUT join("\t",  @$ref), "\n";
          }
    };
if ($@) {
    $dbh->rollback();
    close(OUT);
    print "Error retrieving data\n";
    exit();
    }

# wrap the execute and each fetch individually
eval {
    $sth->execute();
    };
if ($@) {
    $dbh->rollback();
    close(OUT);
    print "Error retrieving data\n";
    exit();
    }

while (1) {

    my $ref;

    eval {
         $ref = $sth->fetchrow_arrayref();
         };
    if ($@) {
         $dbh->rollback();
         close(OUT);
         print "Error retrieving data\n";
         exit();
         }

    print OUT join("\t",  @$ref), "\n";

    }

Reply via email to