所以在我下面的代码中,我不确定我哪里出错了。语法使用不当,变量使用不当?请帮忙!
出于某种原因,我在浏览器中运行它并返回
"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";