Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

DBI HandleError callback not being called

by crazyinsomniac (Prior)
on Jun 02, 2002 at 11:29 UTC ( #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
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? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2019-05-24 07:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (147 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!