PHP异常处理
来源:互联网 发布:淘宝网怎么注册账户 编辑:程序博客网 时间:2024/05/18 21:50
伪代码如下:
try{
do somthing
if somting error
throw exception("Somting bad happened")
}catch(exception){
ouput the exception message
}
也支持创建多个处理器块来解决多个错误。为此,你可以使用各个预定义处理器,或者扩展某个预定义处理器,
创建你自己的处理器。PHP目前只提供一个简单的处理器Exception。
下面是基于多个处理块的伪代码:
try{
do IO somting
if IO somting error
throw IOexception("IO ERROR")
if Numberexception Error
throw Numberexception
}catch(IOexception){
ouput the IOexception message
}catch(Numberexception){
output the Numberexception
}
真是代码:
try{
if(!@mysql_connect('localhost','root','password')){
throw new Exception("数据库连接失败");
}else{
#OK
}
}catch(Exception $e){
echo "someError:".$e->getMessage().'发生在第'.$e->getLine().'行';
}
//下面是多处理器块的演示
try{
if(!@mysql_connect('localhost','root','password')){
throw new Exception("数据库连接失败");
}else{
#OK
if(!mysql_select_db('database'))
throw new DbException("数据库不存在");
}
}catch(Exception $e){
echo "someError:".$e->getMessage().'发生在第'.$e->getLine().'行';
}catch(DbException $e){
echo "错误发生在:".$e->getLine();
}
//DbException是Exception的扩展类。这里没有写出,因为功能与Exception一样
- PHP自定义异常处理
- PHP异常处理
- php异常处理
- PHP异常处理
- PHP异常处理
- PHP 异常处理
- php 异常处理
- PHP异常处理
- php异常处理函数
- PHP 异常处理
- PHP 异常处理
- php 异常处理机制
- PHP异常处理
- php异常处理
- PHP 异常处理
- PHP 异常处理
- PHP异常处理详解
- PHP异常处理详解
- 现代IT人士到了下午上班时,眼睛一定有干涨的感觉吧!一个缓解眼疲劳的好地方
- Windows服务器下设置IIS的常见问题集
- filter所谓的特性
- 定时器T1
- 兼容IE6.0 7.0 8.0 FF上传预览
- PHP异常处理
- asio源码分析
- 从今天开始,记录点东西
- 用Tcpdump抓取MySQL执行的SQL
- windows server 2003 下项目配置步骤
- 如何给单元格加斜线?
- PHP之error_reporting()
- PHP页面输出压缩ob_start()
- 解决opencv中cvCaptureFromFile不能打开一些视频文件