in reply to Tl::MainLoop() catch errors

(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

Replies are listed 'Best First'.
Re: Re: Tl::MainLoop() catch errors
by Anonymous Monk on Feb 20, 2002 at 04:06 UTC
    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).