<?xml version="1.0"?>
<rss version="2.0">
  <channel>
    <title>PHPDeveloper.org</title>
    <link>http://www.phpdeveloper.org</link>
    <description>Up-to-the Minute PHP News, views and community</description>
    <language>en-us</language>
    <pubDate>Sun, 19 May 2013 22:24:08 -0500</pubDate>
    <ttl>30</ttl>
    <item>
      <title><![CDATA[Chris Hartjes: Testing Smells - Try/catch]]></title>
      <guid>http://www.phpdeveloper.org/news/19531</guid>
      <link>http://www.phpdeveloper.org/news/19531</link>
      <description><![CDATA[<p>
In <a href="http://www.littlehart.net/atthekeyboard/2013/04/30/testing-smells-try-catch/">this new post</a> to his site <i>Chris Hartjes</i> gives an example of what he calls a "testing smell". This particular illustration deals with the poor handling of testing and exceptions with try/catch blocks.
</p>
<blockquote>
As part of a project to migrate the PHP code at work from PHP 5.2 to PHP 5.4, I'm using our extensive test suite to look for instances where something that changed between the versions of PHP that we are using has caused some unexpected behaviour. In one of our code bases, I found some tests that are exhibiting a test smell through their use of a try / catch block in the test itself.
</blockquote>
<p>
He includes a (contrived) example showing the use of an exception in a unit test to run an assertion in the "catch" for the test to pass. He points out that this particular check is being done to see if the user input is valid...and that it's a bad way to enforce it using exceptions. He also suggests that if you have an "if" situation, don't use one test with logic in it, write two tests. He mentions a <a href="http://www.brianfenton.us/2011/09/bad-practice-setting-expected.html">disenting opinion</a> but notes that a failing test is a failing test, regardless of what caused the failure.
</p>
Link: http://www.littlehart.net/atthekeyboard/2013/04/30/testing-smells-try-catch]]></description>
      <pubDate>Wed, 01 May 2013 11:42:29 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Joshua Thijssen: PHP5.5: Try/Catch/Finally]]></title>
      <guid>http://www.phpdeveloper.org/news/19169</guid>
      <link>http://www.phpdeveloper.org/news/19169</link>
      <description><![CDATA[<p>
<i>Joshua Thjissen</i> has a new post to his site today about a feature that's been introduced in the upcoming PHP 5.5 release of the language - the addition of "finally" to try/catch exception handling. He gets into it <a href="http://www.adayinthelifeof.nl/2013/02/12/php5-5-trycatchfinally/">a bit more technically</a> than just the "introductory" level, discussing parent/child exception handling and using returns.
</p>
<blockquote>
Exception handling is available in PHP since version 5.  It allows you to have a more fine-grained control over code when things go wrong ie, when exceptions occur. But since PHP 5.5, exception handling has finally evolved into what it should have been from the beginning: the "finally" part has been implemented.
</blockquote>
<p>
He includes a basic example showing how a certain part is always executed, regardless of if the exception is thrown or not. He also shows how a "chained catch" would work to catch multiple kinds of exceptions and when the "finally" is run as it relates to the "trickle down" handling of exceptions. He then gets a little more complex and introduces "return" into the mix. Of special note, even if you return, the "finally" will still get called.
</p>]]></description>
      <pubDate>Tue, 12 Feb 2013 10:03:23 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[Vance Lucas: Handling Exceptions in Gearman Tasks (Even Background Ones)]]></title>
      <guid>http://www.phpdeveloper.org/news/18314</guid>
      <link>http://www.phpdeveloper.org/news/18314</link>
      <description><![CDATA[<p>
<i>Vance Lucas</i> has a quick new post to his site showing you how to <a href="http://www.vancelucas.com/blog/handling-exceptions-in-gearman-tasks-even-background-ones/">handle exceptions in Gearman tasks</a> so that they can be logged correctly as a failure.
</p>
<blockquote>
I recently had some issues with Gearman tasks throwing exceptions and killing the whole Gearman daemon. This made it nearly impossible to trace errors back to their origin, because the logged exception stack trace didn't provide much useful information, because it just logged where it failed in Gearman. [...] The only other place to add code that will catch exceptions for all jobs run is in the GearmanWorker::addFunction method. 
</blockquote>
<p>
To solve the issue, he ends up passing in a closure that takes in the $task and wraps its execution in a try/catch to handle the exception correctly. This is then thrown to a custom exception handler and logged for future diagnosis.
</p>]]></description>
      <pubDate>Fri, 03 Aug 2012 08:28:25 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Ole Markus' Blog: Catching fatal errors in PHP]]></title>
      <guid>http://www.phpdeveloper.org/news/16031</guid>
      <link>http://www.phpdeveloper.org/news/16031</link>
      <description><![CDATA[<p>
<i>Ole Markus</i> has a new post today looking at how you can <a href="http://olemarkus.org/2011/03/catching-fatal-errors-in-php/">catch fatal errors</a> in your PHP applications a bit more gracefully than the usual failure messages.
</p>
<blockquote>
In dynamic languages like PHP [errors like E_ERROR and E_PARSE] happen all the time, for example when trying to call a method on a variable you assumed was an instance of a specific class, but which for some reason suddenly was not instantiated. Not only are they often not catched, but often it is also difficult to even know that they are occurring.
</blockquote>
<p>
His solution comes in the form of a built-in PHP function, <a href="http://php.net/register_shutdown_function">register_shutdown_function</a>, that executes when the PHP process is shutting down - errors or not. It takes in a callback method that has access to an exception object. You can get lots of interesting information from this object and, as in his example, log it to a file for future investigation.
</p>]]></description>
      <pubDate>Fri, 11 Mar 2011 09:16:42 -0600</pubDate>
    </item>
    <item>
      <title><![CDATA[PHP Developer Blog: Unit Tests: How to test for Exceptions]]></title>
      <guid>http://www.phpdeveloper.org/news/12374</guid>
      <link>http://www.phpdeveloper.org/news/12374</link>
      <description><![CDATA[<p>
The PHP Developer Blog has <a href="http://www.phpdevblog.net/2009/04/unit-tests-how-to-test-for-exceptions.html">a quick post</a> for the unit testers out there on how to work with exception handling in your tests.
</p>
<blockquote>
When unit testing, you'd also want to test whether your application throws Exceptions as expected (the following examples are based on SimpleTest). Assumption for the examples is, that we have a method that expects an integer as parameter.
</blockquote>
<p>
Putting the assertion inside of the catch block won't work correctly since it wouldn't happen unless an exception is thrown. Instead he recommends putting it right after the exception try/catch and check to see if the exception variable is a type of 'Exception' (with another potential solution of adding in a check for an 'InvalidArgumentException').
</p>]]></description>
      <pubDate>Mon, 20 Apr 2009 12:06:15 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Quinton Parker's Blog: Try-catch suppress?]]></title>
      <guid>http://www.phpdeveloper.org/news/12176</guid>
      <link>http://www.phpdeveloper.org/news/12176</link>
      <description><![CDATA[<p>
In <a href="http://phpslacker.com/2009/03/19/try-catch-suppress/">this new entry</a> to his blog <i>Quinton Parker</i> looks at some strangeness he's found around the try/catch functionality in PHP. His specific example involves <a href="http://php.net/file_get_contents">file_get_contents</a>.
</p>
<blockquote>
PHP never ceases to amaze me. Just the other day a colleague discovered that you can suppress error messages reported by <a href="http://www.php.net/file_get_contents">file_get_contents()</a> using the try-catch statement. That should've raised an eyebrow.
</blockquote>
<p>
His sample code shows the normal error that a file_get_contents on a nonexistent file would give then wraps it in a try/catch. The same path is put into the file_get_contents but, because of some sort of interesting handling, isn't reported in the catch. He's at a loss and is asking for help figuring this one out from the readers out there. Be sure to <a href="http://phpslacker.com/2009/03/19/try-catch-suppress/#comments">leave a comment</a> if you have more info.
</p>]]></description>
      <pubDate>Fri, 20 Mar 2009 07:56:13 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[DevShed: Sub Classing Exceptions in PHP 5]]></title>
      <guid>http://www.phpdeveloper.org/news/11218</guid>
      <link>http://www.phpdeveloper.org/news/11218</link>
      <description><![CDATA[<p>
DevShed has start up a new series today with <a href="http://www.devshed.com/c/a/PHP/Sub-Classing-Exceptions-in-PHP-5/">the first part</a> in a four-part series looking at exception handling in PHP5.
</p>
<blockquote>
If you do any serious programming, whether it's in PHP 5 or some other language, you've needed to know how to handle run time errors and other "exceptional" conditions. You can do this by making your program throw generic exceptions. Or you can unlock the potential of PHP 5 and learn how to create custom exceptions, which is the subject of this four-part series.
</blockquote>
<p>
In this first part they <a href="http://www.devshed.com/c/a/PHP/Sub-Classing-Exceptions-in-PHP-5/1/">get you started</a> with exceptions, showing how to throw them and catch them correctly (try/catch). They put it to good use in an example catching exceptions thrown from a MySQL connection and select.
</p>]]></description>
      <pubDate>Wed, 15 Oct 2008 12:06:24 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Michelangelo van Dam's Blog: Throwing and catching exceptions]]></title>
      <guid>http://www.phpdeveloper.org/news/11209</guid>
      <link>http://www.phpdeveloper.org/news/11209</link>
      <description><![CDATA[<p>
<i>Michelangelo van Dam</i> has written up <a href="http://www.dragonbe.com/2008/10/throwing-and-catching-exceptions.html">a quick introductory post</a> on his blog about the process around throwing and catching exceptions in your apps.
</p>
<blockquote>
One thing that I noticed was that although the code was well written [in the Zend Framework], implementing coding standards and best practices on many of the classes, I did notice a wrong usage of throwing exceptions (the try - catch statements).
</blockquote>
<p>
He gives a few examples - catching a "divide by zero" the right and wrong way, how to grab/handle the message that comes along with the exception and how to define your own custom exception handler to help your code do more useful things with the errors it might throw.
</p>]]></description>
      <pubDate>Tue, 14 Oct 2008 14:32:59 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Stefan Priebsch's Blog: Turning errors into exceptions]]></title>
      <guid>http://www.phpdeveloper.org/news/10080</guid>
      <link>http://www.phpdeveloper.org/news/10080</link>
      <description><![CDATA[<p>
In a <a href="http://inside.e-novative.de/archives/115-Turning-errors-into-exceptions.html">recent blog entry</a> <i>Stefan Priebsch</i> shows how to take an error thrown by your script and turn it into an exception (to make things like catchable fatal errors).
</p>
<blockquote>
While I would personally prefer an exception to be thrown in the first place, it is pretty easy to convert errors to exceptions in PHP.
</blockquote>
<p>
His example is pretty simple - you set a custom error handler in your script that pulls in the error information and tosses an exception based on the error number the handler is given. Then you can use the try/catch method to see if your script has tossed an exception of the fatal error type. Nice simple solution to handle an interesting little problem.
</p>]]></description>
      <pubDate>Wed, 30 Apr 2008 12:53:35 -0500</pubDate>
    </item>
    <item>
      <title><![CDATA[Martynas Jusevicius' Blog: PHP 5 Features: Exceptions]]></title>
      <guid>http://www.phpdeveloper.org/news/9852</guid>
      <link>http://www.phpdeveloper.org/news/9852</link>
      <description><![CDATA[<p>
On his blog today <i>Martynas Jusevicius</i> <a href="http://www.xml.lt/Blog/2008/03/25/PHP+5+features%3A+Exceptions">talks about</a> a feature that was new in PHP5 - Exceptions:
</p>
<blockquote>
A useful new feature in PHP 5 is <a href="http://devzone.zend.com/node/view/id/1714#Heading5">exception handling</a> via the try/throw/catch paradigm. An exception may be thrown and caught. If an exception is thrown in code surrounded by try, the following statements will not be executed, and the exception will be handled by the first matching catch block.
</blockquote>
<p>
He gives a high-level overview of how Exceptions in PHP5 work and includes a simple example from his work with his <a href="http://www.xml.lt/Resources/Framework">DIY Framework</a>.
</p>]]></description>
      <pubDate>Tue, 25 Mar 2008 10:21:11 -0500</pubDate>
    </item>
  </channel>
</rss>
