13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

566 Chapter 26 Debugging<br />

Listing 26.2 contains a script that declares an error h<strong>and</strong>ler, sets the error h<strong>and</strong>ler using<br />

set_error_h<strong>and</strong>ler(), <strong>and</strong> then generates some errors.<br />

Listing 26.2 h<strong>and</strong>le.php—This Script Declares a Custom Error H<strong>and</strong>ler <strong>and</strong><br />

Generates Different Errors<br />

<br />

The output from this script is shown in Figure 26.1.<br />

This custom error h<strong>and</strong>ler does not do any more than the default behavior. Because<br />

you write this code, you can make it do anything.You have a choice about what to tell<br />

your visitors when something goes wrong <strong>and</strong> how to present that information so that it<br />

fits the rest of the site. More importantly, you have the flexibility to decide what happens.<br />

Should the script continue? Should a message be logged or displayed? Should tech<br />

support be alerted automatically?

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!