")
// Catch IOexception
} catch(IOexception) {
output the IOexception message
}
CHAPTER 8 ?– ERRO R AND EXCEPTION HANDL ING 223
// Catch Numberexception
} catch(Numberexception) {
output the Numberexception message
}
If you??™re new to exceptions, such a syntactical error-handling standard seems like
a breath of fresh air. The next section applies these concepts to PHP by introducing
and demonstrating the variety of new exception-handling procedures made available
in version 5.
PHP??™s Exception-Handling Implementation
This section introduces PHP??™s exception-handling feature. Specifically, I touch upon the
base exception class internals and demonstrate how to extend this base class, define
multiple catch blocks, and introduce other advanced handling tasks. Let??™s begin with
the basics: the base exception class.
Extending the Base Exception Class
PHP??™s base exception class is actually quite simple in nature, offering a default
constructor consisting of no parameters, an overloaded constructor consisting of
two optional parameters, and six methods. Each of these parameters and methods
is introduced in this section.
The Default Constructor
The default exception constructor is called with no parameters. For example, you can
invoke the exception class like so:
throw new Exception();
Once the exception has been instantiated, you can use any of the six methods
introduced later in this section.
Pages:
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302