课程笔记
课程/PHP/后端开发
那些年你遇到的错误与异常
介绍
章节
问答
笔记
慕盖茨4467426
2017-12-19
经典(这个视频可以看看)
截图
0赞 · 0采集
搭上最后一班车
2017-05-08
需要主动抛出异常 throw之后的语句不会执行 try后必须有catch,否则解析错误
0赞 · 0采集
只差一点点
2017-04-02
ssss
0赞 · 0采集
weibo_蓉芳107_03763669
2016-11-19
<?php header("content-type:text/html;charset=utf8"); /* try{ 代码段; throw new Exception('异常信息') }cathch(Exception $e){ echo $e->getMessage(); } */ error_reporting(-1); $num=NULL; try{ $num=3/0; var_dump($num); }catch(Exception $e){ echo $e->getMessage(); $num=12; } echo '<hr/>'; echo 'continue...'; var_dump($num); echo '<hr/>'; try{ $num1=3; $num2=0; if($num2==0){ throw new Exception('0不能当作除数'); echo 'this is a test';//看不到 }else{ $res=$num1/$num2; } }catch(Exception $e){ echo $e->getMessage(); } echo '<hr/>'; try{ if($username=='king'){ echo 'hello king'; }else{ throw new Exception('非法管理员'); } }catch(Exception $e){ echo $e->getMessage(); echo '<hr/>'; } echo 'continue...'; ?>
1赞 · 1采集
异常代码
2016-11-06
Php不像java提供了很多异常类,所以很多异常都会当成错误。 要想变错误为抛出异常,需要手动throw异常对象
0赞 · 0采集
gardener
2016-02-01
需要主动抛出异常 throw之后的语句不会执行 try后必须有catch,否则解析错误
截图
0赞 · 0采集
gardener
2016-02-01
异常例子 下面例子触发错误,没有捕捉到异常
截图
0赞 · 0采集
APPLE007
2015-09-02
PHP不会主动捕获异常,需要程序中抛出 (throw),才能捕获。
0赞 · 0采集
数据加载中...