PHP,例外

Bla*_*ext 0 php exception-handling

我正在研究W3schools的例外在这个链接上,在标题之前的链接内:

"重新抛出异常"

有句话说:

"如果抛出的异常是类CustomException并且没有customException catch,只有基本异常catch,那么异常将在那里处理."

如果能有人请给我一个这句话的例子,我将非常感激.

Joh*_*nde 7

基本上他们会说如果你没有设置一个catch语句来捕获customException它将会落入一般的Exceptioncatch语句.

在此示例中,第一个catch语句将捕获,customException因为它明确地设计为这样做.

try {
    // fail
    throw new customException();
}
catch (customException $e) {
    // catch custom exception
}
catch (Exception $e) {
    // catch any uncaught exceptions
}
Run Code Online (Sandbox Code Playgroud)

在下一个示例中,因为它缺少通用Exceptioncatch块的子句将捕获它:

try {
    // fail
    throw new customException();
}
catch (Exception $e) {
    // catch any uncaught exceptions
}
Run Code Online (Sandbox Code Playgroud)