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 were 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, well need to revisit the SignatureImage class that we built over the past few articles.  Throughout that code, we youll 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 Im 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 images analytics.  Until next time, keep coding!



 
 
>>> 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: