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

コードが行っていることは、誰かをゴルフ ボールで殴り、「フォア!」と叫ぶようなものです。

于 2013-01-20T17:48:46.367 に答える