Closed wangvisual closed 7 years ago
The catching of exceptions is expected behavior, I think perhaps the best solution to your problem is for you to use Exception objects in your code that will capture the stack trace you want. Then the FATAL call would get the correct exception information coming from the exact location it occurred. Does that make sense?
Thanks for the hint, now I'm try to use SIG{DIE} or override core::die, following the article at http://www.effectiveperlprogramming.com/2011/05/override-die-with-end-or-coreglobaldie/
I tried override $SIG{__DIE__} and it works. Override core::die does NOT work as it's only for die() calls, can't catch run-time errors.
Now the exceptions happen in 'then' will be treat as reject and the reject handler will be called later, eg:
$promise->then( sub { _RUN_TIME_ERRORHERE; })->then(undef, sub { FATAL @; });
The FATAL will be called with something like: Can\'t use string ("1455362825.71571") as an ARRAY ref while "strict refs" in use at /depot/perl-5.22.0/lib/5.22.0/x86_64-linux/Time/HiRes.pm line 74
But IMHO, exception is different with reject as later is the one that author intend to do so. Also in my application I would like to print the whole call stack when error happens, but now the error stack is like:
[STACK] Package => main, File => a.pl, Line => 602, Sub => CommonUtil::FATAL Package => Promises::Deferred, File => .../lib/perl5/Promises/Deferred.pm, Line => 133, Sub => main::ANON Package => Promises::Deferred, File => .../lib/perl5/Promises/Deferred.pm, Line => 136, Sub => (eval) Package => Promises::Deferred::EV, File =>.../lib/perl5/Promises/Deferred/EV.pm, Line => 19, Sub => Promises::Deferred::ANON Package => main, File => a.pl, Line => 934, Sub => Promises::Deferred::EV::ANON Package => main, File => a.pl, Line => 934, Sub => (eval) Package => main, File => a.pl, Line => 1667, Sub => main::main
But what I want is to have the FATAL to show the line for _RUN_TIME_ERROR_HERE, so either
Sorry for my English :-)
Thanks.