PHP VERSION: 8.2.18

throwable_interface_type_error.php

<?php
// throwable interface: TypeError
// TODO:
// from Chris Langton to All Participants:
// declaring a class name again cant be caught it seems

function add(int $leftint $right) {
    return 
$left $right;
}

try {
    echo 
add('left''right');
} catch (
TypeError $e) {
    
// Log error and end gracefully
    
echo 'Error: did not supply the correct type!';
} catch (
Exception $e) {
    
// Handle any exceptions
    
echo 'Unknown Error';
}
echo 
PHP_EOL;

Output


Error: did not supply the correct type!
SOURCE CODE