<?php
class Oss {
public static function connect() {
throw new Exception("oss connect error");
return 'oss object';
}
}
//调用三层
class S3{
public static function connect() {
//throw new Exception("s3 connect error");
return 's3 object';
}
}
//调用二层
function callReader($class,$url){
try{
$conn=call_user_func_array(array($class, "connect"),array());
return $conn;
}catch(Exception $e){
throw $e;
}finally{
//无论如何都会执行,在这记录日志
}
}
//调用一层
function getMessage(){
$conn=null;
try {
$conn=callReader('Oss',"http://xxxx");
} catch (Exception $e1) {
$conn=callReader('S3',"http://xxxx");
}
return $conn;
}
//最先的入口
try{
var_dump(getMessage());
}catch(Exception $e){}【课程推荐:PHP视频教程】
以上就是try catch在PHP中的使用的详细内容,更多请关注Gxl网其它相关文章!
查看更多关于trycatch在PHP中的使用的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://haodehen.cn/did62906