HomePHP 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.
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.
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.
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!