http://qs321.pair.com?node_id=535142


in reply to Catching DBI (or other) errors

You could write it as

$query->execute() or do { $SQL_FAIL = 1};
But for a single line statement, you really don't need the braces, just :
$query->execute() or $SQL_FAIL = 1;
But why are you doing it this way?

This means that you then have to check the value of SQL_FAIL every line before processing the next statement.

Wrapping it all in an eval and using RaiseError really works a treat, looks clean makes your life simpler.

If you are using the value of SQL_FAIL to figure out what statement failed, then you could go the other way and have $sql_stage (note, not all in capitals because this implies a constant, which it isn't) and you could just set $sql_stage to the current stage you're working on. As in
my $sql_stage=1; eval { $query->execute(); $sql_stage = 2; $query2->execute(); $sql_stage = 3; $query3->execute(); }; if ($@) { if ($sql_stage < 3) { $fix1->execute(); } else { $fix2->execute(); } }