我正在尝试学习 PHP,我刚刚转到异常,当我尝试从
http://php.net/manual/en/language.exceptions.php
Example #2 Exception handling with a finally block
我得到一个错误
Parse error: syntax error, unexpected '{' in C:\xampp\htdocs\test\filename.php on line 13
<?php
function inverse($x) {
if (!$x) {
throw new Exception('Division by zero.');
}
else return 1/$x;
}
try {
echo inverse(5) . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
} finally {
echo "First finally.\n";
}
try {
echo inverse(0) . "\n";
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
} finally {
echo "Second finally.\n";
}
// Continue execution
echo 'Hello World';