Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

try catch php

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

try {
    echo inverso(5) . "
";
    echo inverso(0) . "
";
} catch (Exception $e) {
    echo 'and the error is: ',  $e->getMessage(), "
";
}
 
PREVIOUS NEXT
Tagged: #catch #php
ADD COMMENT
Topic
Name
4+3 =