Home arrow PHP arrow Building a Modular Exception Class in PHP 5

Building a Modular Exception Class in PHP 5

Welcome to the final part of the four-part series “Subclassing exceptions in PHP 5.” By means of a hands-on approach, this series walks you through using inheritance to build finely-tuned exception subclasses. These subclasses can be used to handle, via multiple “try-catch” blocks, several failures that might occur during the execution of a given web application.

TABLE OF CONTENTS:
  1. Building a Modular Exception Class in PHP 5
  2. Review: Handling MySQL-related exceptions with two subclasses
  3. Centralizing the processing of MySQL-related exceptions
  4. Handling MySQL-related exceptions through one single subclass
By: Alejandro Gervasio
Rating: starstarstarstarstar / 2
November 05, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Introduction

Working with generic exceptions in PHP 5 is a fairly easy process that can be tackled with minor hassles. This is true even if you're starting to get your hands dirty developing web applications that utilize them to handle a certain number of critical conditions.

Things can be a bit more complicated, however, when it's necessary to work with customized exceptions. This specific situation requires that you derive some exception subclasses from the built-in one provided by PHP 5, and that you use multiple "try-catch" blocks within the same application.

Of course, if you're an experienced PHP 5 developer with a solid background in working with exceptions, then you've probably mastered them already. However, if you're just getting started with employing them in your own applications, and want to know how to build a customized exception mechanism in a few simple steps, then this article series might be what you need.

Now, getting straight to the point, you'll possibly recall that in the last article I demonstrated how to build a customized exception system in PHP 5, which had the capacity to catch not only generic exceptions, but a couple of additional ones, triggered when working specifically with MySQL.

In short, the system in question was smart enough to handle two well-differentiated kinds of exceptions: first, the ones triggered when connecting to the MySQL server, selecting a particular database, and running SQL queries; and second, exceptions that could be thrown when manipulating result sets.

Nonetheless, handling the aforementioned types of exceptions demanded the use of two different subclasses, which in a case like this is really unnecessary. Therefore, in this concluding article of the series, I'm going to implement a similar MySQL exception mechanism, but this time by using only one subclass.

So, are you ready to tackle the final chapter of this educational journey? Let's begin now!



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: