0
让我们来看看下面的代码:例外的继承在PHP
class customException extends Exception{}
$a;
try{
if(!$a)
throw new customException("Variable not initialize");
echo $a;
}
catch(customException $e){
echo $e->getMessage();
}
Catch块的工作,我们得到的屏幕上的错误文本,但是如果我改变了catch(customException $e)
上catch(Exception $e)
这将是工作......为什么?我们抛出了类customException
的例外,为什么它会工作?
解释我请
异常冒泡基本上所有的自定义异常在他们的核心是简单的例外,所以它是有道理的,如果你考虑它。 – Andrew