Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Catch a type error either as a type error, an error, or a throwable
<?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
You can’t perform that action at this time.