Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

DBI HandleError callback not being called

by crazyinsomniac (Prior)
on Jun 02, 2002 at 11:29 UTC ( [id://171010]=perlquestion: print w/replies, xml ) Need Help??

crazyinsomniac has asked for the wisdom of the Perl Monks concerning the following question:

Hi. Why isn't my HandleError callback being called?
( and yes, I know i could local $SIG{__WARN__}, but that's what HandleError is for)
use strict; use DBI; ##$SIG{__WARN__} = sub { die "warning why\n\n".shift(@_) }; { my $db_user = 'null'; #read only my $db_pass = 'nullnull'; my $db_name = 'null'; # the name of the db my $db_host = 'localhost'; my $db_driver = 'mysql'; my $db_serverstr = "DBI:$db_driver:$db_name"; my $db_h = DBI->connect( "$db_serverstr", "$db_user", "$db_pass", { HandleError => sub { die "WHYYYY\n".shift(@_) }}, ); } __END__ DBI is 1.201 This is perl, v5.6.1 built for MSWin32-x86-multi-thread
p.s. i did do a mighty google but to no avail ;(

 
______crazyinsomniac_____________________________
Of all the things I've lost, I miss my mind the most.
perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"

Replies are listed 'Best First'.
(jeffa) Re: DBI HandleError callback not being called
by jeffa (Bishop) on Jun 02, 2002 at 15:11 UTC
    i don't _think_ you can do that. The problem is that you need a handle before you can access the 'HandleError' attribute. You can't even set $DBI::errstr or $DBI::err. There _might_ be a way of tricking Perl into 'reblessing' an object, but i think you will have to settle for something along the lines of:
    { my $db_h = DBI->connect( $db_serverstr, $db_user, $db_pass, {HandleError => sub {die "WHYYYY\n".shift(@_)} } ) or die "WHYYYY\n" . $DBI::errstr; my $sth = $db_h->selectall_arrayref(' grab me stuff from that table '); }
    'HandleError' will be used for all subsequent errors.

    UPDATE
    'RaiseError' will not magically make this work - i thought that it would at first, as well that you need to turn 'PrintError' off, which you don't.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
Re: DBI HandleError callback not being called
by Aristotle (Chancellor) on Jun 02, 2002 at 15:12 UTC
    Maybe you need RaiseError => 1?
    Update: Doh, jeffa++ beat me to it, and his point makes more sense too.
    ____________
    Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://171010]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-25 17:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found