The first thing I'd point out is that if your connect worked but an error occurred later the arguments to the HandleError sub are 1. error string 2. the db handle being used when the fail occurred and 3. the first value returned by the failing method. Your HandleError sub seems to assume it is going to get a message/error string and a database name which it is ONLY going to get IF you call it like on line 23 of your example and not IF DBI calls it.
The second thing to point out is that if you have not connected then there is no connection handle passed to HandleError so the 2nd argument will be a DBI::dr, instead. e.g.,
perl -MDBI -le 'use Data::Dumper; sub he {print Dumper(\@_);};my $h =
+DBI->connect("dbi:ODBC:does_not_exist", undef, undef, {HandleError =>
+ \&he});'
$VAR1 = [
'DBI connect(\'does_not_exist\',\'\',...) failed: [unixODBC]
+[Driver Manager]Data source name not found, and no default driver spe
+cified (SQL-IM002)',
bless( {}, 'DBI::dr' ),
undef
];
Lastly, you are calling your own handle_error if connect fails so at that point you already know the connect failed. Your lines 18 to 23 will end in handle_error being called twice if connect fails. |