Answers for "try catch not handling exception php"

PHP
1

try catch php

function inverso($x) {
    if (!$x) {
        throw new Exception('Zero division.');
    }
    return 1/$x;
}

try {
    echo inverso(5) . "n";
    echo inverso(0) . "n";
} catch (Exception $e) {
    echo 'and the error is: ',  $e->getMessage(), "n";
}
Posted by: Guest on December-13-2020
5

php try catch

<?php

function test() {
    try {
        throw new Exception('foo');
    } catch (Exception $e) {
        return 'catch';
    } finally {
        return 'finally';
    }
}

echo test();
?>
Posted by: Guest on January-13-2021
0

catch any exception php

try {
  // call a success/error/progress handler
} catch (Throwable $e) { // For PHP 7
  // handle $e
} catch (Exception $e) { // For PHP 5
  // handle $e
}
Posted by: Guest on November-15-2021

Code answers related to "try catch not handling exception php"

Browse Popular Code Answers by Language