"Wiggins D'Anconia" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > ------------------------------------------------ > On Wed, 17 Sep 2003 12:49:28 -0400, Dan Anderson <[EMAIL PROTECTED]> wrote: > > > Do you mean that you set a debug bool at the beginning of the file and > > if (main::$debug) { spit_out_error(); } or you just don't output errors > > at all? Doesn't that make debugging much harder? > >
Use some type of carp equivalent to do error handling. That way you can implement different debugging levels and even call stack dumps by simple use() statements. I recommend Carp::Clan: http://search.cpan.org/author/STBEY/Carp-Clan-5.1/Clan.pod > > Sort of, in general I was talking more about catching and handling the error rather than printing or not printing it, meaning that rather than letting DBI do the error handling for me, I would rather catch the error myself and then throw the exception myself depending on what I am doing. Then in my exception I attach the message from DBI (when I want to, which for me is always, but your method would work as well to turn it on and off) using something like $dbh->errstr or $DBI::errstr or $sth->errstr depending on where the error occurred. That way I get the messages to help with debugging, but have complete control over what the "handling an exception" really does. > RTFM for the HandleError property of DBI objects: http://search.cpan.org/author/TIMB/DBI-1.38/DBI.pm#DBI_Utility_Functions Scroll down to $h->{HandleError}... You can set it to a code ref that is called when a DBI exception is thrown. Read the docs very carefully, you can design arbitrarily complex error handling for the DBI: sub DBIErrorHandler { my($description, $error) = @_; BaseModule::Debug::log(4, "DBI error: $description"); return( 1 ); } my($dbh) = DBI->connect( ... ); $dbh->{HandleError} = \&BaseModule::Config::DBIErrorHandler; It is really slick. For instance, you can chain arbitrary error handlers, or depending on whether your error handler returns true or false, you can control the builtin DBI handlers. The DBI has one of the better error handling mechanisms found on the CPAN. It should probably be filtered out and made into its own distro. Todd W. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]