docs(worker): Prefer `try-catch` over `set_exception_handler` by Slamdunk · Pull Request #1897 · php/frankenphp

@Slamdunk

@Slamdunk

@alexandre-daubois

I wonder if this should be in the minimal example as you did or as a note after the snippet. It definitely makes sense to mention it somewhere, just wondering if it's the right place as this snippet is about the minimal worker code to make it work.

@Slamdunk

My thought process is the chances of a project to be so advanced to leverage worker mode and still not ever set once a custom exception handler by set_exception_handler is... zero.

I got bitten very hard in production by this, and I would have loved it to be documented as a baseline

alexandre-daubois

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, works for me

@dunglas

I suggest to reword the comment. set_exception_handler does work as expected in a worker script.

Maybe something like:

// Catch and handle the exception and handle it

I would add a note later about exception handlers, like:

> ![NOTE]
>
> Exception handlers are called only when the worker script ends, which may not be what you expect (use `try`/`catch` in this case).

WDYT?

@Slamdunk

I'm not a native english speaker, so I'm fine with any change request you are asking me, as long as the set_exception_handler word is mentioned somewhere

@Slamdunk

@Slamdunk

I have rephrased the comment so there's no wrong or bad concepts anymore, as you suggested

dunglas

alexandre-daubois

@alexandre-daubois

@Slamdunk Slamdunk deleted the worker_mode_set_exception_handler branch

October 6, 2025 07:02