hi
I'd like to learn to program good perl ...
I think one element to achieve that is to provide hirarchichal exceptions. But since this is something that is not included in Perl, I try to use the 'Exception::Class' module. For some reasons it's hard for me to find a start.
I've tried to write a simple script with a classic x/0 error:
#!/usr/bin/env perl
use Exception::Class
( 'MyException' );
# try
eval {
(my $result = (23/0)) ||
MyException->throw( error => 'I feel funny.' ) };
# my $e;
# catch
if ( my $e = Exception::Class->caught('MyException') )
{
warn $e->error, "\n", $e->trace->as_string, "\n";
warn join ' ', $e->euid,
$e->egid, $e->uid, $e->gid, $e->pid, $e->time;
exit;
}
else
{
$e = Exception::Class->caught();
ref $e ? $e->rethrow : die $e;
}
But the error is not catched by my custom exception handling, but by some system error. Output
perl "exception-class-test.pl"
Illegal division by zero
but I look for
I feel funny
Any ideas?
thanks in advance.
ben
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.