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

Re: Carp not working after change to objects

by snoopy (Deacon)
on May 16, 2008 at 04:06 UTC ( #686853=note: print w/ replies, xml ) Need Help??


in reply to Carp not working after change to objects

You've ommitted to set RaiseError => 1 in your DBI connect attributes.

Therefore this has been raised as a warning not an error. That's why it's not being caught by CGI::Carp's error handler.

Update: The following code illustrates, this.

#!/usr/bin/perl use warnings; use strict; use CGI::Carp qw/fatalsToBrowser/; use DBI; # Without RaiseError #line 100 my $dbh1 = DBI->connect("dbi:SQLite:my.db","","",); $dbh1->do("select * from crud"); # bad query on $dbh1 # With RaiseError #line 200 my $dbh2 = DBI->connect("dbi:SQLite:my.db","","",{RaiseError => 1}); $dbh2->do("select * from crud"); # bad query on $dbh2
The CGI::Carp handler error handler doesn't get invoked until the bad query on $dbh2.


Comment on Re: Carp not working after change to objects
Download Code
Replies are listed 'Best First'.
Re^2: Carp not working after change to objects
by cosmicperl (Chaplain) on May 16, 2008 at 14:03 UTC
    Thanks for the reply, but I'm pretty sure that's not it. I want DBI to just give me a warning, it's my own code that does a Croak. (I don't want to croak in all situations of a DBI's carp).
      Sorry this didn't help.

      Btw, I'm not able exactly replicate your error with my Sqlite driver. My prepare statement on an unknown table returns undef, not a valid statement handle.

      my $sth = $dbh1->prepare("insert into guff values (1,2,3)") or croak "prepare error" # dies here for me

      If you're not raising errors, be aware that prepare may return undef.

      Also consider localisd error handling. You still has the option of dieing or continuing:

      my $dbh = DBI->connect(... ,{RaiseError => 1}); do { local $SIG{__ERROR__} = \&my_handler; # database code }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://686853]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (17)
As of 2015-07-30 15:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls