Skip to content

Instantly share code, notes, and snippets.

@scottsb
Last active September 11, 2015 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save scottsb/9c4ca7fc74c4697628bd to your computer and use it in GitHub Desktop.
Save scottsb/9c4ca7fc74c4697628bd to your computer and use it in GitHub Desktop.
Hack to handle multiple Exception types with a single block
<?php
class Foo extends Exception {}
class Bar extends Exception {}
class Baz extends Exception {}
try {
throw new Foo();
} catch (Exception $e) {
switch (get_class($e)) {
case 'Foo':
case 'Bar':
echo 'Case 1';
break;
case 'Baz':
echo 'Case 2';
break;
default:
throw $e;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment