<!DOCTYPE html>
<html>
<title>Exception</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<body>
<a href="../index.php">返回首页</a>
<hr></hr>
<?php
//create function with an exception
function checkNum($number){
if($number>1){
throw new Exception("值必须<1");
}
return true;
}
//trigger exception
#checkNum(2);
//在 "try" 代码块中触发异常
try{
checkNum(2);
//If the exception is thrown, this text will not be shown
echo '值<=1';
}//捕获异常
catch(Exception $e){
echo 'Message: ' .$e->getMessage();
}
?>
</body>
</html>