in reply to script dies with 'broken pipe'-message, even in eval

try replacing ..
my $retval = eval { $dbh->execute(@values); }; unless ($retval) { _db_recover(); }
with...
eval { $dbh->execute(@values); }; if ($@) { _db_recover(); }

Replies are listed 'Best First'.
Re: Re: script dies with 'broken pipe'-message, even in eval
by eXile (Priest) on May 25, 2004 at 17:00 UTC
    The code:
    eval { $dbh->execute(@values); }; if ($@) { _db_recover(); }
    was actually my first try. But there was nothing in $@ , so _db_recover() was never executed. The returnvalue-for-eval did the trick and at least got the _db_recover() function executed.
      Ah! I see an issue.
      you are using a database handle ($dbh) to execute something. execute is a method for a statement handle ($sth). Also...
      How are you setting up your database connection?
      Are you setting RaiseError?
      $dbh = DBI->connect( 'dbi:Oracle:tnsname', 'userid', 'password', {RaiseError => 1} );
      If not you would have to check for an error after every call like ...
      $sth->execute(@args) || die $sth->errstr();
      Instead of being able to trap errors in an eval
        Hi,

        I'm sorry, the '$dbh->execute' was a typo, I fixed it in the original question.

        My $dbh is initialised like this:

        $dbh = DBI->connect($sql_dsn, $sql_schema, $sql_auth); $dbh->{LongReadLen} = $LongReadLen;
        Don't think the LongReadLen has anything to do with this.

        I haven't tried using RaiseError, but then the question still remains why my eval doesn't trap the 'broken pipe' error? I don't want my program to die that easily on me.