CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [terrykhatri531] Perl DBI - Error handling: Edit Log



Zhris
Enthusiast

Aug 29, 2014, 10:15 AM


Views: 4108
Re: [terrykhatri531] Perl DBI - Error handling

Your error is caused because $sth is undefined, which occurs before the if statement that tests if there was a statement error. There should never be a circumstance under which you try to use an undefined statement handler, you should have died beforehand.

You can trap fatal errors within an eval block, if an error occurs it will be available in the special variable $@ (or $EVAL_ERROR if using English):


Code
eval 
{
# some expression
};
if ( my $error = $@ )
{
# do something with $error.
}


Note there can be issues with the preservation of $@ etc, Try::Tiny handles error trapping more reliably.

Finally, there is excellent information regarding handling DBI errors here.

Chris


(This post was edited by Zhris on Aug 29, 2014, 11:47 AM)


Edit Log:
Post edited by Zhris (Enthusiast) on Aug 29, 2014, 10:39 AM
Post edited by Zhris (Enthusiast) on Aug 29, 2014, 10:42 AM
Post edited by Zhris (Enthusiast) on Aug 29, 2014, 10:47 AM
Post edited by Zhris (Enthusiast) on Aug 29, 2014, 10:50 AM
Post edited by Zhris (Enthusiast) on Aug 29, 2014, 11:47 AM
Post edited by Zhris (Enthusiast) on Aug 29, 2014, 11:47 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives