Wednesday, March 4, 2015

OCPJP7 Exception Handling



  1. Closeable (Java 5) throws IOException

    AutoCloseable (Java 7) throws Exception

  2. Closeable extends AutoCloseable.

  3. try-with-resources : close when get out of the try block in reverse order.

  4. If more than one exception is thrown in a try-with-resources block

    All later exception will be added as suppressed.

  5. try {

    }catch(Exception 1 | Exception 2 e) {

    }

    There should be no subclass relationship between Exception 1 and Exception 2. Do not assign a new value to "e" in multi-catch.

  6. If exception throws in catch block or finally block, no suppressions happen.

    The last exception thrown get sent to the caller.

  7. If a method throws a exception in the declaration, it must be included in try catch block. Even if it is in the finally block.


  8. Try-with-resource Object must not have close method if that Object is declared in Try block.

No comments:

Post a Comment