Hi everyone!
I've got exception handling subsystem which converts dies to exceptions with stack trace using Exception::Class-like lib.
my $base_class = '...'; # base class for exceptions
my $error_class = '...'; # my error class
sub rethrow(;$) {
my $e = @_ ? $_[0] : $@;
die $e
if blessed( $e ) && $e->isa( $base_class );
die $error_class->new( $e );
}
sub try(&) {
my $code = $_[0];
eval {
local $SIG{__DIE__} = \&rethrow;
&$code();
};
$@;
}
And usage is:
my $e = try {
# some code, potentially with errors
};
Exception objects supports stringification. For most cases it works fine, but there is one case which breaks it.
If I had module which dies duering loading and i'll try to require it with my try fucntion, $SIG{__DIE__} handler will be called twice. And second time it will be called with stringified exception from first time! So I lose call stack collected in first call and error location is lost.
Is there any way to prevent such stringification?
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.