Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Tl::MainLoop() catch errors

by Anonymous Monk
on Feb 20, 2002 at 01:42 UTC ( [id://146469]=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks,

I noticed that MainLoop() seems to catch errors before I do. For example if I execute a messed up DBI call or maybe call a object method that doesn't exist...

Does this make sense? Is there a way I can catch them first? (I need to handle the error gracefully ;-)

thanks for any suggestions!!!

Replies are listed 'Best First'.
Re: Tl::MainLoop() catch errors
by rjray (Chaplain) on Feb 20, 2002 at 02:14 UTC

    (I assume you meant Tk::MainLoop.)

    The Tk module has to necessarily catch fatal errors, as there is a lot of cleaning up to do in the graceful shutting down of a GUI. What you should do is wrap the potentially-problematic lines of code in eval {} blocks, then check for errors by examining $@.

    --rjray

      Thanks!

      I have a followup question...it seems I need to call die() to get the eval{} to catch the error...maybe it is DBI specific though...I guess I don't understand who is "raising" the error to eval {} me or some library code??? ($@ doesn't catch an error unless I call die() eventhough the library is printing error messages...)

      eval { my $dbh = DBI->connect("bad stuff here")...|| die "dead"; } if($@) { print "ERROR" }

        Well, if the call to DBI->connect() doesn't cause a fatal error, can't you just examine the value of $dbh to see if there was an internal error that was by nature non-fatal? Of course, you probably don't want to be declaring $dbh to be a lexical within the scope of the eval {}... I would think you want the handle if the connect succeeds.

        --rjray

        If you set $DBI::RaiseError to 1, the exceptions are raised for you (i.e. DBI calls die).

Re: Tl::MainLoop() catch errors
by screamingeagle (Curate) on Feb 20, 2002 at 02:15 UTC
    Could you please elaborate on what exactly you're trying to do ? your post is a bit vague And posting some code always helps :-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-24 08:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found