diff --git a/docs/worker.md b/docs/worker.md index 81c18266..e055436d 100644 --- a/docs/worker.md +++ b/docs/worker.md @@ -78,9 +78,15 @@ $myApp->boot(); // Handler outside the loop for better performance (doing less work) $handler = static function () use ($myApp) { - // Called when a request is received, - // superglobals, php://input and the like are reset - echo $myApp->handle($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER); + try { + // Called when a request is received, + // superglobals, php://input and the like are reset + echo $myApp->handle($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER); + } catch (\Throwable $exception) { + // `set_exception_handler` is called only when the worker script ends, + // which may not be what you expect, so catch and handle exceptions here + (new \MyCustomExceptionHandler)->handleException($exception); + } }; $maxRequests = (int)($_SERVER['MAX_REQUESTS'] ?? 0);