PHP
  Home arrow PHP arrow Intercepting Customized Exceptions in PHP 5
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Intercepting Customized Exceptions in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2008-10-22


    Table of Contents:
  • Intercepting Customized Exceptions in PHP 5
  • Triggering customized exceptions in PHP 5
  • Deriving a subclass from the built-in Exception class
  • Intercepting some MySQL-related exceptions

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Intercepting Customized Exceptions in PHP 5
    ( Page 1 of 4 )

    Welcome to the second part of a four-part series on sub classing exceptions in PHP 5. In the first part of this series, you learned how to build a basic processing class which could throw customized exceptions to client code. What you haven't yet learned, however, is how to build the code to catch these exceptions. That is the topic of this article.

    Introduction

    As you probably know, one of the most relevant improvements incorporated into the object model of PHP 5 is the capacity for triggering and intercepting exceptions by way of conventional "try-catch" blocks. This feature facilitates the handling of different error conditions via a compact, highly-centralized mechanism.

    While the built-in exception system that comes bundled natively with PHP 5 is usually good enough to handle errors and other critical conditions during the execution of a given web application, it's worthwhile to mention that there are a number of additional cases where it is necessary to implement an exceptions system that can handle different failures in a more specific way.

    That's precisely where exception subclasses come in. It's possible to derive a few different child classes from the base "Exception" built-in class, which allows us to build specific exception handling modules within a single PHP 5-driven application.

    Of course, if you already read the introductory article of this series, then hopefully you'll be familiar with building classes that are capable of triggering customized exceptions in the context of a concrete PHP 5 application. As you'll certainly recall, in the course of that tutorial, I demonstrated how to define a basic MySQL-processing class which could throw MySQL-related exceptions to client code, instead of using only generic ones.

    Indeed, building a class like the one described above is a straightforward process that doesn't require you to have the sharpest skills for using the object-oriented parading with PHP 5. This only gives us half of the picture, however, since it's also necessary to implement an exception mechanism that is capable of catching these customized, MySQL-related exceptions via a conventional "try-catch" block.

    The mechanism in question can be quickly constructed by deriving a subclass from the parent "Exception" that comes included with PHP 5. Therefore, in the next few lines I'm going to teach you how perform this process in an approachable fashion, so you can start incorporating exception sub classes into your own PHP 5 applications in very short time. Let's begin now!



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

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT