Errors

Table of Contents

Introduction

Sadly, no matter how careful we are when writing our code, errors are a fact of life. PHP will report errors, warnings and notices for many common coding and runtime problems, and knowing how to detect and handle these errors will make debugging much easier.

add a note

User Contributed Notes 1 note

up
0
Anonymous
29 days ago
<?php

// You might not be able to notice that a "Fatal error" occurred in some cases.

try{

throw new
Exception('An exception!');

}catch (
Exception $e){

undefined_function(); // causes a "Fatal error"

}finally{

$html = <<<HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
<div style="margin:15em 1em">
<p>Even if you remove "die()" at the end of this script,
<p>in case that Finally block shows you a window-height content,
<p>you might not be able to notice
<p>that a "Fatal error" occurred.
</div>
</body>
</html>
HTML;

echo
$html;
die();
// if you remove this line, you can see the "Fatal error" message about undefined_function(). But in case "Finally block" shows you a window-height content, it might be difficult to notice that a fatal error occurred because the "Fatal error" message appears after the Finally block process (in PHP 8.3.10).

}
To Top