0

我正在准备 SCWCD 考试。我对这个问题有疑问。

Web 应用程序部署描述符中的哪两个是有效的?(选择两个。)

    A. <error-page>
        <exception-type>*</exception-type>
        <location>/error.html</location>
       </error-page>
    B. <error-page>
        <exception-type>java.lang.Error</exception-type>
         <location>/error.html</location>
      </error-page>
    C. <error-page>
        <exception-type>java.lang.Throwable</exception-type> 
        <location>/error.html</location></error-page>
    D. <error-page>
            <exception-type>java.io.IOException</exception-type>
            <location>/error.html</location>
        </error-page>
    E. <error-page>
            <exception-type>NullPointerException</exception-type>
             <location>/error.html</location>
        </error-page>

正确答案是 CD。但是为什么 java.lang.Error 不能有效,因为 Error 是 Throwable 的子类。

4

1 回答 1

0

From the JavaDoc of Error and Exception classes:

An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch. Most such errors are abnormal conditions [...]

The class Exception and its subclasses are a form of Throwable that indicates conditions that a reasonable application might want to catch [...]

It has nothing to do with their types, it is more like a design choice.

于 2012-11-02T19:12:36.280 回答