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

Implementing the custom exception - 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

In order to implement our newly-created custom exception, we’ll need to revisit the SignatureImage class that we built over the past few articles.  Throughout that code, we you’ll see instances of errors being thrown as shown below.

        $url = "http://twitter.com/statuses/user_timeline/{$name}.xml?count=1";

        $xml = $this->curlRequest($url);

        if ($xml === false) {

            throw new Exception('User feed unavailable.');

        }

Implementing our new custom exception is as simple as editing the line that throws a native Exception and updating it with our custom exception instead.

        $url = "http://twitter.com/statuses/user_timeline/{$name}.xml?count=1";

        $xml = $this->curlRequest($url);

        if ($xml === false) {

            throw new SignatureImageException('User feed unavailable.');

        }

And there you have it!  Now instead of receiving error messages as text in the browser, they are built into an image to maintain compatibility with the expected output of our SignatureImage class.

Here again we part with a fully-functioning application.  But I’m coming back for one more article in this series in which I will show you how to boost the performance of this application, overcome a pitfall in the Twitter API, and add a method of monitoring your image’s analytics.  Until next time, keep coding!



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

blog comments powered by Disqus
   

PHP ARTICLES

- 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...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 6 - Follow our Sitemap

Dev Shed Tutorial Topics: