Skip to content

Instantly share code, notes, and snippets.

@wouterj
Created April 18, 2014 13:45
Show Gist options
  • Select an option

  • Save wouterj/11044979 to your computer and use it in GitHub Desktop.

Select an option

Save wouterj/11044979 to your computer and use it in GitHub Desktop.
<?php
// src/Acme/DemoBundle/Exception/AcmeDemoException.php
namespace Acme\DemoBundle\Exception;
/**
* Special interface for AcmeDemoBundle exceptions
*/
interface AcmeDemoException
{
}
<?php
// src/Acme/DemoBundle/Exception/InvalidArgumentException.php
namespace Acme\DemoBundle\Exception;
/**
* The InvalidArgumentException for the AcmeDemoBundle, it implements the AcmeDemoException interface.
*/
class InvalidArgumentException extends \InvalidArgumentException implements AcmeDemoException
{
}
<?php
// src/Acme/OtherBundle/Exception/AcmeOtherException.php
namespace Acme\OtherBundle\Exception;
/**
* Special interface for AcmeOtherBundle exceptions
*/
interface AcmeOtherException
{
}
<?php
// src/Acme/OtherBundle/Exception/InvalidArgumentException.php
namespace Acme\OtherBundle\Exception;
/**
* The InvalidArgumentException for the AcmeOtherBundle, it implements the AcmeOtherException interface.
*/
class InvalidArgumentException extends \InvalidArgumentException implements AcmeOtherException
{
}
@wouterj

wouterj commented Apr 18, 2014

Copy link
Copy Markdown
Author

Now you can throw the correct exception class and catch all of them for one bundle using:

try {
    // ...
} catch (AcmeDemoException $e) {
    // acmedemobundle exceptions
} catch (AcmeOtherBundle $e) {
    // acmeotherbundle exceptions
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment