Ro888
0
Q:

php catch exception


<?php
  
try {
	raiseErrorFunction();
	echo 'no error';
}
catch(Exception $e) {
	echo 'Message: ' . $e->getMessage();
}

?>
11

<?php
function inverse($x) {
    if (!$x) {
       throw new Exception('Division durch Null.');
    }
    return 1/$x;
}

try {
    echo inverse(5) . "\n";
    echo inverse(0) . "\n";
} catch (Exception $e) {
    echo 'Exception abgefangen: ',  $e->getMessage(), "\n";
}

// Ausführung fortsetzen
echo "Hallo Welt\n";
?>

0
try
{
    // Some code...
}
catch(AError | BError $e)
{
    // Handle exceptions
}
catch(Exception $e)
{
    // Handle the general case
}
0

New to Communities?

Join the community