Last active
September 11, 2015 22:01
-
-
Save scottsb/9c4ca7fc74c4697628bd to your computer and use it in GitHub Desktop.
Hack to handle multiple Exception types with a single block
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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