CKTIS / PHP
Throwable
Interface commune à Error et Exception pour traiter les deux hiérarchies.
Version : PHP 8.4; repository runtime, production runtime not attested
Syntaxe
catch (Throwable $failure) { /* inspect cause */ }Interface commune à Error et Exception pour traiter les deux hiérarchies. Fournit message, code, cause précédente et trace. Une classe utilisateur doit hériter de Error ou Exception pour être Throwable. Ciblez un type plus étroit si un seul est attendu.
$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"]]
Exemples
<?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);
Résultat
[["LogicException","L"],["TypeError","T"]]