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