11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

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

www.it-ebooks.infoC H A P T E R 8• • •Error and Exception HandlingEven if you wear an S on your chest when it comes to programming, errors will undoubtedly creep intoall but the most trivial of applications. Some of these errors are programmer-induced, the result ofmistakes made during the development process. Others are user-induced, caused by the end user’sunwillingness or inability to conform to application constraints. For example, the user might enter12341234 when asked for an e-mail address, obviously ignoring the intent of the request. Yet regardlessof the error’s source, your application must be able to react to such unexpected errors in a gracefulfashion, hopefully doing so without losing data or crashing the application. In addition, your applicationshould be able to provide users with the feedback necessary to understand the reason for such errorsand potentially adjust their behavior accordingly.This chapter introduces several features <strong>PHP</strong> has to offer for handling errors. Specifically, thefollowing topics are covered:Configuration directives: <strong>PHP</strong>’s error-related configuration directives determi<strong>net</strong>he language’s error-handling behavior. Many of these directives are introduced inthis chapter.Error logging: Keeping a running log is the best way to record progress regardingthe correction of repeated errors and to quickly identify newly introducedproblems. In this chapter, you learn how to log messages to both your operatingsystem’s logging daemon and a custom log file.Exception handling: Prevalent among many popular languages (Java, C#, andPython, to name a few), exception handling was added to <strong>PHP</strong> with the version 5release, and further enhanced within version 5.3. Exception handling offers astandardized process for detecting, responding to, and reporting errors.Historically, the development community has been notoriously lax in implementing properapplication error handling. However, as applications continue to grow increasingly complex andunwieldy, the importance of incorporating proper error-handling strategies into your daily developmentroutine cannot be overstated. Therefore, you should invest some time becoming familiar with the manyfeatures <strong>PHP</strong> has to offer in this regard.Configuration DirectivesNumerous configuration directives determine <strong>PHP</strong>’s error-reporting behavior. Many of these directivesare introduced in this section.175

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

Saved successfully!

Ooh no, something went wrong!