Answers for "how to use exception to catch error in php"

PHP
0

php catch fatal error

try {
   do some thing evil
} catch (Error $e) {
   echo 'Now you can catch me!';
}
Posted by: Guest on June-08-2020
0

php catch exception

<?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";
?>
Posted by: Guest on August-03-2020

Code answers related to "how to use exception to catch error in php"

Browse Popular Code Answers by Language