Skip to content

Instantly share code, notes, and snippets.

@wouterj
Created January 15, 2015 13:58
Show Gist options
  • Select an option

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

Select an option

Save wouterj/74f762b27e08ea4e6b34 to your computer and use it in GitHub Desktop.
<?php
$response = new \Response();
try {
$client->buy('sofa');
} catch (\Exception $e) {
foreach ($this->exceptionHandlers as $handler) {
if ($handler->accepts($e)) {
$response = $handler->handle($e, $response);
}
}
}
return $response;
<?php
class NoProductsLeftHandler implements ExceptionHandler
{
public function accepts(\Exception $e)
{
return $e instanceof NoProductsLeft;
}
public function handle(\Exception $e, Response $response)
{
return new RedirectResponse('back');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment