How do you re-throw an exception in a `catch` block?

Responsive Ad Header

Question

Grade: Education Subject: Support
How do you re-throw an exception in a `catch` block?
Asked by:
52 Viewed 52 Answers
Responsive Ad After Question

Answer (52)

Best Answer
(333)
You can re-throw an exception in a `catch` block using the `throw` keyword. This is useful when you want to log the exception or perform some cleanup, but still allow the exception to propagate up the call stack to be handled by a higher-level error handler. Example: `catch (Exception $e) { logError($e->getMessage()); throw $e; }`