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.

198 Chapter 7 Error <strong>and</strong> Exception H<strong>and</strong>ling<br />

Listing 7.3<br />

Continued<br />

}<br />

}<br />

<br />

";<br />

try<br />

{<br />

throw new myException("A terrible error has occurred", 42);<br />

}<br />

catch (myException $m)<br />

{<br />

echo $m;<br />

}<br />

?><br />

In this code, you declare a new exception class, called myException, that extends the<br />

basic Exception class.The difference between this class <strong>and</strong> the Exception class is that<br />

you override the __toString() method to provide a “pretty” way of printing the<br />

exception.The output from executing this code is shown in Figure 7.2.<br />

Figure 7.2<br />

The myException class provides exceptions with<br />

“pretty printing.”

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

Saved successfully!

Ooh no, something went wrong!