[ create a new paste ] login | about

Link: http://codepad.org/WesToSfO    [ raw code | output | fork ]

PHP, pasted on Oct 29:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
function inverse($x) {
    if (!$x) {
        throw new Exception('Division by zero.');
    }
    else return 1/$x;
}

try {
    echo inverse(5) . "\n";
    echo inverse(0) . "\n";
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "\n";
}

// Continue execution
echo 'Hello World';
?>


Output:
1
2
3
0.2
Caught exception: Division by zero.
Hello World


Create a new paste based on this one


Comments: