CKTIS / PHP
Ključna riječ try
Obuhvaća operacije barem jednim blokom catch ili finally.
Verzija: PHP 8.4; repository runtime, production runtime not attested
Sintaksa
try { process(); } catch (Throwable $e) { recover($e); }Obuhvaća operacije barem jednim blokom catch ili finally. Ako operacija baci iznimku, ostatak try se preskače i izvršava se prvi odgovarajući catch. Bez odgovarajućeg catch iznimka se širi nakon pripadajućeg finally.
$steps=[]; try {$steps[]="start";throw new RuntimeException();$steps[]="end";}catch(RuntimeException){$steps[]="caught";}finally{$steps[]="cleanup";} echo json_encode($steps);
["start","caught","cleanup"]
Primjeri
<?php
$steps=[]; try {$steps[]="start";throw new RuntimeException();$steps[]="end";}catch(RuntimeException){$steps[]="caught";}finally{$steps[]="cleanup";} echo json_encode($steps);
Rezultat
["start","caught","cleanup"]