Throwing exception within exception handler

后端 未结 5 1174
温柔的废话
温柔的废话 2021-02-19 18:44

I have a script with an exception handler. This exception handler cleans up a couple connections, prior to the script exiting after an exception.

I would like to re-thr

5条回答
  •  后悔当初
    2021-02-19 19:26

    Just catch the exception and log the message yourself, then rethrow.

    try {
        $foo->doSomethingToCauseException();
    } catch (Exception $e) {
        error_log($e->getMessage());
        throw $e;
    }
    

    If you bubble up to the top and PHP is unable to handle, it will result in uncaught exception.

提交回复
热议问题