1.使用的关键字
try:检测代码
catch:发现异常
throw:抛出异常信息
finally:无论有无异常都会执行 可以省掉
Exception:异常类
下面是php手册中的
<!doctype html><html><head><meta charset="utf-8"><title>无标题文档</title></head><body><?phpif(!empty($_POST['button'])){try{$ceshi=$_POST['test'];if($ceshi=='')throw new Exception('神马,不说话就是默认我是帅比了',1001);if($ceshi=='不帅')throw new Exception("错误,你撒谎!", 1002);echo '是的 0ne最帅了!~!';}catch(Exception $ex){echo '错误信息:'.$ex->getMessage(),'<br>';echo '错误码:'.$ex->getCode(),'<br>';echo '文件地址:'.$ex->getFile(),'<br>';echo '错误行号:'.$ex->getLine(),'<br>';}finally{}}?><form method="post" action="">0ne帅不帅: <input type="text" name="test"> <br /><input type="submit" name="button" value="提交"></form></body></html>

