Subject: | When CATCH_EXCEPTIONS => 0, exceptions in IO events are not propagated |
There seems to be a bug in exception handling, including the latest POE release (1.368) when running under CATCH_EXCEPTIONS => 0.
The expected behavior is - if an unhandled exception is encountered when POE::Kernel is processing events, that exception should cause the entire program to crash out and for Perl's default exception handling to run.
It seems that POE::Kernel runs events inside an eval{} and defers exceptions with $kr_exception. If POE::Kernel::run is invoked as opposed to run_one_timeslice, loop_run ends up being the loop and there's no $kr_exception check taking place if the kernel is purely processing IO events (eg, via _data_handle_enqueue_ready).
On the other hand, if an unhandled exception happens inside an event that was invoked by sending a message (eg, yield/post) then _data_ev_dispatch_due will notice and stop the kernel so that the $kr_exception can be rethrown.
This is easily demonstrated by having an IO event handler (eg, one attached to the read event of a wheel) throw an exception. With CATCH_EXCEPTION => 0, assuming there are not other events this exception does not break out of loop_run, etc. However, if the IO event handler merely yields another event which does the same processing, the event loop is broken correctly and the exception is reported by Perl.