Therefore, a general overview is presented regarding the matter. If you??™re already
familiar with the basic concepts, feel free to skip ahead to the PHP-specific material
later in this section.
Why Exception Handling Is Handy
In a perfect world, your program would run like a well-oiled machine, devoid of both
internal and user-initiated errors that disrupt the flow of execution. However, programming,
like the real world, remains anything but an idyllic dream, and unforeseen events
that disrupt the ordinary chain of events happen all the time. In programmer??™s lingo,
these unexpected events are known as exceptions. Some programming languages have
the capability to react gracefully to an exception by locating a code block that can
handle the error. This is referred to as throwing the exception. In turn, the error-handling
code takes ownership of the exception, or catches it. The advantages to such a
strategy are many.
For starters, exception handling essentially brings order to the error-management
process through the use of a generalized strategy for not only identifying and reporting
application errors, but also specifying what the program should do once an error is
encountered. Furthermore, exception-handling syntax promotes the separation
of error handlers from the general application logic, resulting in considerably more
organized, readable code. Most languages that implement exception handling abstract
the process into four steps:
1.
Pages:
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300