Home arrow PHP arrow Page 3 - A Custom Exception Class for Dynamic Twitter Signature Images with PHP

Building a custom exception interface - PHP

Welcome to part four of a five-part series on creating a dynamic Twitter signature image in PHP. In the last segment, I showed you how to implement PHP 5 exceptions as an error-handling mechanism in your signature image application. Today we’re going to expand upon that concept by creating a custom exception class for handling error states in our application.

TABLE OF CONTENTS:
  1. A Custom Exception Class for Dynamic Twitter Signature Images with PHP
  2. Examining the SignatureImage class
  3. Building a custom exception interface
  4. Building the custom exception
  5. Implementing the custom exception
By: Nilpo
Rating: starstarstarstarstar / 3
August 27, 2009

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

To begin piecing together a custom exception, you’ll first need to understand how the native Exception class is constructed.  For that you’ll need to sit down and examine the PHP documentation, so I’ll save you a little time.

interface ExceptionInterface

{

    public function __construct($message = null, $code = 0);

   

    public function getMessage();        // message of exception

    public function getCode();           // code of exception

    public function getFile();           // source filename

    public function getLine();           // source line

    public function getTrace();          // an array of the backtrace()

    public function getTraceAsString();  // formatted string of trace

   

    public function __toString();        // formatted string for display

}

In the code above I’ve created an interface that lists all of the methods provided by the native Exception class.  By implementing this interface in our own custom exception class, we’ll have a framework to ensure that our own exception is constructed in the same manner as the original. 

In larger applications, this allows multiple developers to implement any custom exception without the need for additional documentation.  That’s an important time-saver any time you have more than one developer collaborating on a project.

Now that we’ve got an interface to define our custom exceptions, we can begin putting the code together to make it work.



 
 
>>> More PHP Articles          >>> More By Nilpo
 

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: