Base di conoscenzaCentro esami
ITItaliano
Scegli la lingua13

CKTIS / PHP

Error

Classe base degli errori del motore come TypeError e ValueError.

Versione: PHP 8.4; repository runtime, production runtime not attested

Sintassi

catch (Error $error) { /* handle engine error */ }

Classe base degli errori del motore come TypeError e ValueError. Implementa Throwable ed è un ramo parallelo a Exception. catch(Exception) non intercetta Error. Gli avvisi ordinari non diventano automaticamente oggetti Error.

try { strlen([]); }
catch(Exception $e){echo "exception";}
catch(Error $e){echo json_encode([get_class($e),$e instanceof Throwable,$e instanceof Exception]);}
["TypeError",true,false]

Esempi

<?php
try { strlen([]); }
catch(Exception $e){echo "exception";}
catch(Error $e){echo json_encode([get_class($e),$e instanceof Throwable,$e instanceof Exception]);}

Risultato

["TypeError",true,false]

Fonti