Created
July 14, 2016 13:10
-
-
Save ThijsFeryn/7611b79e9812d89fe9e017421f2a8b67 to your computer and use it in GitHub Desktop.
Catch a type error either as a type error, an error, or a throwable
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 | |
function double(int $argument):int { | |
return $argument*2; | |
} | |
try { | |
var_dump(double([3])); | |
} catch (TypeError $e) { | |
echo "Caught as type error: ".$e->getMessage().PHP_EOL; | |
} | |
try { | |
var_dump(double([3])); | |
} catch (Error $e) { | |
echo "Caught as error: ".$e->getMessage().PHP_EOL; | |
} | |
try { | |
var_dump(double([3])); | |
} catch (Throwable $e) { | |
echo "Caught as throwable: ".$e->getMessage().PHP_EOL; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment