That doesn't make sense. Exceptions such as the one you provided are caught by eval and don't print anything.
>perl -we"$a=10; $a->isa('foo');"
Can't call method "isa" without a package or object reference at -e li
+ne 1.
>perl -we"eval { $a=10; $a->isa('foo'); }"
>
So you either used a bad example or you have a buggy __DIE__ handler. (It should check $^S.)
Assuming you just picked a bad example, eval doesn't affect warnings, which can be avoided with writing a warning handler
>perl -we"eval { $a='abc'; $a += 5; }
Argument "abc" isn't numeric in addition (+) at -e line 1.
>perl -we"eval { local $SIG{__WARN__} = sub {}; $a='abc'; $a += 5 }"
>
Of course, that neither eval nor a warning handler prevents from writing to STDERR in general. local *STDERR; will handle most cases. The exception would be if you spawned a child process.
>perl -we"eval { print STDERR qq{foo\n}; }"
Argument "abc" isn't numeric in addition (+) at -e line 1.
>perl -we"eval { local *STDERR; print STDERR qq{foo\n}; }"
print() on unopened filehandle STDERR at -e line 1.
>perl -we"eval { local $SIG{__WARN__} = sub {}; local *STDERR; print S
+TDERR qq{foo\n}; }"
print() on unopened filehandle STDERR at -e line 1.
>
By the way, you can avoid the need for any of shenanigans in this particular case by using isa as a function.
>perl -we"$a=10; UNIVERSAL::isa($a, 'foo');"
>
|