<?php
function inverse($x) {
if (!$x) {
throw new Exception('被除数不能为0');
}
if ($x>31) {
throw new Exception('月数不能大于31');
}
return 1/$x;
}
try
{
echo inverse(5) . "<hr>";
echo inverse(10) . "<hr>";
echo inverse(2) . "<hr>";
echo inverse(0) . "<hr>";
}
catch (Exception $e)
{
echo '错误提示: ', $e->getMessage(), "<hr>";
}
?>