Created
October 10, 2014 13:22
-
-
Save bramus/47dad1ed98102f767aaa to your computer and use it in GitHub Desktop.
PHP Exception Typehinting
This file contains 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 DummyException extends Exception { | |
// ... | |
} | |
class Dummy { | |
public function __construct() { | |
throw new Exception('...'); | |
} | |
} | |
class Dummy2 { | |
public function __construct() { | |
throw new DummyException('...'); | |
} | |
} | |
try { | |
// $d = new Dummy(); | |
$d = new Dummy2(); | |
} catch(DummyException $e) { | |
echo 'DummyException caught' . PHP_EOL; | |
} catch(Exception $e) { | |
echo 'Exception caught' . PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment