CKTIS / PHP
Throwable
Interfaz común de Error y Exception para tratar ambas jerarquías.
Versión: PHP 8.4; repository runtime, production runtime not attested
Sintaxis
catch (Throwable $failure) { /* inspect cause */ }Interfaz común de Error y Exception para tratar ambas jerarquías. Ofrece mensaje, código, causa anterior y traza. Una clase propia debe heredar de Error o Exception para ser Throwable. Usa un catch específico si solo esperas un 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"]]
Ejemplos
<?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);
Resultado
[["LogicException","L"],["TypeError","T"]]