Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

Error

Error is the base of PHP engine error objects such as TypeError and ValueError.

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

Syntax

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

Error is the base of PHP engine error objects such as TypeError and ValueError. It implements Throwable and is a sibling of Exception. A catch for Exception alone therefore misses an Error. Ordinary warnings are separate diagnostics and do not become Error objects automatically.

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]

Examples

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

Result

["TypeError",true,false]

Sources