Photography
Computing
Tags
Filters
Templates
I have been writing some code again (it's been a long time) and I stumbled upon a situation dealing with unknown/unexpected errors (die) in code I didn't write. Now I remembered having used some code looking like this a while ago:
$SIG{qq{__DIE__}} = sub
{
# display stack trace here
...
}
Now that snipped didn't work anymore as it seemes that the perl implementations has deprecated this kind of handling. So what's next?
Fortunately ex::override and Devel::StackTrace rescued me.
I added following snippet at the beginning of the code as it seems logical to override die before it happens.
use Devel::StackTrace;
use ex::override GLOBAL_die => sub
{
local *__ANON__ = "custom_die";
print
'Error: ', @_, "\n",
"Stack trace:\n",
Devel::StackTrace->new(no_refs => 1)->as_string, "\n";
exit 1;
};
That is not a 100% solution as this does not handle undef errors but it gave me enough information about what I did wrong to be able to fix it.
Discussion