CKTIS / PHP
Ključna beseda try
Obda operacije z vsaj enim blokom catch ali finally.
Različica: PHP 8.4; repository runtime, production runtime not attested
Sintaksa
try { process(); } catch (Throwable $e) { recover($e); }Obda operacije z vsaj enim blokom catch ali finally. Če operacija vrže izjemo, se preostanek try preskoči in izvede se prvi ustrezni catch. Brez ustreznega catch se izjema širi naprej po pripadajočem finally.
$steps=[]; try {$steps[]="start";throw new RuntimeException();$steps[]="end";}catch(RuntimeException){$steps[]="caught";}finally{$steps[]="cleanup";} echo json_encode($steps);
["start","caught","cleanup"]
Primeri
<?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"]