Prev | Current Page 291 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

However, only four will be of any use; the other two
are useful only if you instantiate the class with the overloaded constructor, introduced
next.
The Overloaded Constructor
The overloaded constructor offers additional functionality not available to the
default constructor through the acceptance of two optional parameters:
224 CHAPTER 8 ?–  ERRO R AND EXCEPTION HANDL ING
message: Intended to be a user-friendly explanation that presumably will be passed
to the user via the getMessage() method, introduced in the following section.
error code: Intended to hold an error identifier that presumably will be mapped to
some identifier-to-message table. Error codes are often used for reasons of internationalization
and localization. This error code is made available via the getCode()
method, introduced in the next section. Later you??™ll learn how the base exception
class can be extended to compute identifier-to-message table lookups.
You can call this constructor in a variety of ways, each of which is demonstrated here:
throw new Exception("Something bad just happened", 4)
throw new Exception("Something bad just happened");
throw new Exception("", 4);
Of course, nothing actually happens to the exception until it??™s caught, as demonstrated
later in this section.
Methods
Six methods are available to the exception class:
getMessage(): Returns the message if it is passed to the constructor.


Pages:
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303