0

所以在我下面的代码中,我不确定我哪里出错了。语法使用不当,变量使用不当?请帮忙!

出于某种原因,我在浏览器中运行它并返回

"Fatal error: Uncaught exception 'numexception' with message 'The numbers are not set' in C:\xampp\htdocs\php_testing\test.php:29 Stack trace: #0 {main} thrown in C:\xampp\htdocs\php_testing\test.php on line 29".

我不明白我的代码哪里出错了???

class numexception extends Exception{}

function multiply($a,$b){
     echo $a*$b;
}


$var1 = 5;
//$var2 = 2; as you can see variable 2 is not set as I commented it out to test
//the exception

if(!isset($var1) or !isset($var2)){
  throw new numexception("The numbers are not set");
}

try{
    multiply($var1,$var2);
}
catch(numexception $e){
    echo "This exception was caught:".$e->getMessage();
}

echo "The script then continues";
4

1 回答 1

5

throw不在 中,因此try无法catch编辑。

您的代码所做的就像用高尔夫球击打某人,然后大喊“Fore!”。

于 2013-01-20T17:48:46.367 回答