我的项目中没有很多异常.
现在,(我们使用MVC)我的try catch包含了我的整个代码:
现在,(我们使用MVC)我的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
}
}