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!
blog comments powered by Disqus |