HomePHP A Custom Exception Class for Dynamic Twitter Signature Images with PHP
A Custom Exception Class for Dynamic Twitter Signature Images with 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.
The code you have for this application so far is fully functional and includes full error-handling. You may be wondering what the need is for a custom exception class in the first place. So I’d like to take a moment to discuss why I’ve chosen to create one.
This application serves a single purpose. It accepts an input and delivers an image to the browser. In the event of an error, the script halts execution and displays that error.
The problem lies in this difference in output.
The calling page is expecting an image and therefore won’t display the error text. So to make this useful, it might be a good idea to deliver the error text as an image instead.
Since this only needs to be done in the event an exception occurs in our application, it makes sense that the code to produce this image should reside in a custom exception. This also provides an opportunity to explore a little deeper into PHP 5’s error handling capabilities.
For those readers that are just now tuning in, let’s take a look at the code we have so far. On the next page you'll see the SignatureImage class in its entirety.