CKTIS / PHP
Throwable
Interfaccia comune a Error ed Exception per gestire entrambe le gerarchie.
Versione: PHP 8.4; repository runtime, production runtime not attested
Sintassi
catch (Throwable $failure) { /* inspect cause */ }Interfaccia comune a Error ed Exception per gestire entrambe le gerarchie. Offre messaggio, codice, causa precedente e traccia. Una classe utente deve derivare da Error o Exception per essere Throwable. Restringi catch se è atteso un solo tipo.
$types=[];
foreach([new LogicException("L"),new TypeError("T")] as $problem){ try{throw $problem;}catch(Throwable $e){$types[]=[get_class($e),$e->getMessage()];} }
echo json_encode($types);
[["LogicException","L"],["TypeError","T"]]
Esempi
<?php
$types=[];
foreach([new LogicException("L"),new TypeError("T")] as $problem){ try{throw $problem;}catch(Throwable $e){$types[]=[get_class($e),$e->getMessage()];} }
echo json_encode($types);
Risultato
[["LogicException","L"],["TypeError","T"]]