Answers for "what is the use of try catch function in 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

Code answers related to "what is the use of try catch function in php"

Browse Popular Code Answers by Language