1)
{
throw new Exception("Value must be 1 or below");
}
return true;
}
//在 "try" 代码块中触发异常
try
{
checkNum(2);
//If the exception is thrown, this text will not be shown
echo 'If you see this, the number is 1 or below';
}
//捕获异常
catch(**Exception $e**)
{
echo 'Message: ' .$e->getMessage();
}
?>
php是弱类型语言,catch中为什么要写Exception $e ,而不是直接写$e
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
对,有点像java