<?php
function ActionSend($mobile, $key='')
{
try
{
/* if (empty($key)) {
throw new Exception('key值不能为空');
}
if($key != 'adfasdfdasfs') {
throw new Exception('key值不一致');
}
echo 'oo';
*/
echo 1/0;
echo "throw";
//throw new Exception ( "Method not exists!" );
}
catch(Exception $e)
{
print_r($e);
echo "xxx";
}
}
ActionSend('15801668635','adfasdfdasfs');
?>
输出:
Warning: Division by zero in E:\wamp\www\test\try.php on line 16
throw
本文通过一个PHP脚本示例展示了如何使用try-catch结构来处理运行时异常,特别是当除数为零时引发的警告。

2785

被折叠的 条评论
为什么被折叠?



