最好的做法是尝试 – 抓住我的整个PHP代码,或尽可能具体?
发布时间:2020-05-25 09:36:42 所属栏目:PHP 来源:互联网
导读:我的项目中没有很多异常. 现在,(我们使用MVC)我的try catch包含了我的整个代码: try{ fronController::dispatch($somthing...);}catch(Exception $E){ //handle errors} 我想知道是否有一个很好的理由使用尽可能具体的try-catch块,我可以或只是保持一般现在
|
我的项目中没有很多异常.
try{
fronController::dispatch($somthing...);
}catch(Exception $E){
//handle errors
}
我想知道是否有一个很好的理由使用尽可能具体的try-catch块,我可以或只是保持一般现在吗? 通常在本地抛出,捕获全局,除非异常处理程序特定于一个函数,在这种情况下本地处理.class fooException extends Exception{}
// DB CLASS
public function Open(){
// open DB connection
...
if ($this->Conn->connect_errno)
throw new fooException("Could not connect: " . $this->Conn->connect_error);
}
// MAIN CLASS
public final function Main(){
try{
// do stuff
}
catch(fooException $ex){
//handle fooExceptions
}
} (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
