Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Exception Safe Perl

by PerlingTheUK (Hermit)
on Aug 15, 2005 at 23:14 UTC ( #484020=perlquestion: print w/replies, xml ) Need Help??

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

Dearest Monks,

It has taken me several years that I have given in on a topic and cannot see any option but to include more than simple exception catching in my code. So far all I did was setup a log file and hand out debug versions that would come with an config file that writes a very high detail log file that I could normally interpret to find the errors.

However I am currently importing and converting a file that quite regularly was edited manually and does not quite live uf to its tight formatting standards.

I have seen packages that go a lot further than the standard eval{}; or $SIG{ __DIE__ } = &\catch_me basics and would like to make use of a relatively robust and basic one. However at the same timeI have a list of requirements:

  1. Class independent default types: I need to be able to define standard exception types a la "ArrayIndexOutOfBounds" , "StringContainsOnlyNumericCharacters", etc.
  2. I need integration into TK to display error messages
  3. I need to be able to set up different kinds of error levels due to different kind of debug levels. E. g. report all expected behaviour for internal testing and report fatal for client only.

What are other users using? I am interested in your answers.


Replies are listed 'Best First'.
Re: Exception Safe Perl
by xdg (Monsignor) on Aug 15, 2005 at 23:36 UTC

    I definitely recommend starting with Exception::Class. Among other things, its ability to let you define a hierarchy of exceptions should simplify what is necessary for some of your objectives (independent default types and different "levels" of errors).

    Update: I just noticed Simon Cozen's new article "Ten Things You (Probably) Didn't Know About Perl" on TPJ. It mentions the sigtrap pragma as another way of trapping signals. YMMV.


    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

Re: Exception Safe Perl
by valdez (Monsignor) on Aug 16, 2005 at 10:43 UTC

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://484020]
Approved by Old_Gray_Bear
Front-paged by friedo
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2022-06-30 17:34 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (98 votes). Check out past polls.