Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
<?php function processPayment(array $order): void { try { $gateway->charge($order["amount"]); } catch (GatewayException $e) { // Log with context before re-throwing $this->logger->error("Payment failed for order #{$order["id"]}", [ "exception" => $e->getMessage(), "amount" => $order["amount"], ]); throw $e; // Rethrow — let caller decide what to do } } // PHP 8: bare throw re-throws the current exception try { riskyOp(); } catch (Exception $e) { cleanup(); throw; // Re-throws $e without needing the variable }
Result
Open