Given a method that might fail with warnings and / or errors, I want the error method to be displayed by the caller. Fir enter this script:
foo(0);
sub foo {
1 / shift;
}
Throws an error Illegal division by zero at foo.pl line 4, but I want to Illegal division by zero at foo.pl line 1. There should be several ways if I put this method in a module, or if I wrap my method body in eval, but I did not find a simple way:
sub foo {
attributeErrorsToCaller;
1 / shift;
}
Is there such a way?
EDIT: mirod answer is not close to what I was looking for:
Foo::foo(0);
package Foo;
use diagnostics -traceonly;
BEGIN { disable diagnostics; }
sub foo {
enable diagnostics;
1 / shift;
}
No enable diagnosticserror message Illegal division by zero at foo.pl line 9.. With enable diagnosticsit it is still too verbose, but it can also be useful:
Uncaught exception from user code:
Illegal division by zero at foo.pl line 10.
at foo.pl line 10
Foo::foo(0) called at foo.pl line 2
, "hack" , , , , .