CKTIS / PHP
Throwable
Spoločné rozhranie Error a Exception pre obe hierarchie.
Verzia: PHP 8.4; repository runtime, production runtime not attested
Syntax
catch (Throwable $failure) { /* inspect cause */ }Spoločné rozhranie Error a Exception pre obe hierarchie. Ponúka správu, kód, predchádzajúcu príčinu a stopu zásobníka. Vlastná trieda musí pre Throwable dediť z Error či Exception. Ak očakávate jediný druh, zachyťte užší typ.
$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"]]
Príklady
<?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);
Výsledok
[["LogicException","L"],["TypeError","T"]]