Exception Best Practices in PHP 5.3

http://ralphschindler.com/2010/09/15/exception-best-practices-in-php-5-3

// usage of bracket syntax for brevity
namespace MyCompany\Component {

    interface Exception
    {}

    class UnexpectedValueException 
        extends \UnexpectedValueException 
        implements Exception
    {}

    class Component
    {
        public static function doSomething()
        {
            if ($somethingExceptionalHappens) {
                throw new UnexpectedValueException('Something bad happened');
            }
        }
    }

}

Leave a Reply