use Exception::Class ('MyException');
sub test {
MyException->throw(error => 'Test');
}
eval {
my $x = bless {}, 'X';
test($x);
};
if($@) {
print 2;
}
sub X::DESTROY {
print 1;
}
You would expect it to print '12' but it prints '21'. The problem is that Exception::Class stores full stack trace in exception object including all arguments passed to subs. I.e. it creates additional reference on them what means their destructors will not be called until your undefine or change $@. Any ideas how to fix/workaround it?
Ask MattS (Score:1)
Basically, closures + exceptions are a bad thing. This needs to be documented better somewhere in Perl.
-Dom
Re:Ask MattS (Score:1)
Ilya Martynov (http://martynov.org/ [martynov.org])
Re:Ask MattS (Score:1)
-Dom
A quick work around... (Score:3, Informative)
Reply to This
Re:A quick work around... (Score:1)
Real fix is probably using weak refs to store args in stack trace or don't store store them at all. After all Exception::Class needs stack trace only to print error message for uncaught exceptions. It could just generate error message at the moment when exceptions is raised and do not store stack trace in exception objec
Ilya Martynov (http://martynov.org/ [martynov.org])
Ahem, it's in the docs (Score:2)
This will pass along the no_refs parameter to all Devel::StackTrace objects created, and no references will be stored.
This should perhaps be the default, though.
-dave
Re:Ahem, it's in the docs (Score:1)
Making it default is definetely good idea.
Ilya Martynov (http://martynov.org/ [martynov.org])