我是PHP新手,在浏览php.net时,发现了这段代码:
<?php
function inverse($x) {
if (!$x) {
throw new Exception('Division by zero.');
}
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\n";
?>
$e
是什么?它可以被重命名吗?它的作用是什么?为什么我们需要它?
$e
只是一个保存“异常(Exception)”对象的变量,是可以改名的。 - cmorrissey