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";
在蘇格蘭它跟隨着「你這個混蛋」 –
所以你說扔新的異常進入try塊? –
這正是我所說的。 –