Answers for "OOP Error Handling In PHP - Exceptions & Try Catch Finally Blocks"

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

Code answers related to "OOP Error Handling In PHP - Exceptions & Try Catch Finally Blocks"

Browse Popular Code Answers by Language