2019-12-2 exception caught

Capture normal and abnormal java pop abnormal different people catch the exception, the following program will still continue

Syntax: generating a shortcut alt + shift + z

        the try { 
          capture range of 
        } the catch (Exception E) { 
       exception handling ... e.printStackTrace (); }
the finally { anyway block are executed }

try ... catch ... finall running order

When no abnormality try block, after the try block finishes running catch block skip is not performed, run directly following statements.

When there is an abnormality in the try block, the try block operation exception statement to jump directly to the corresponding catch block, if there is finally performed after the last executed finally.

finally statement block is always the last to be executed, even if there is return

If there are a plurality of different types of exceptions need to be captured in the try block

Solution two kinds:

1. Direct catch exceptions Exception class can be a parent

2. sequentially capturing a plurality of abnormality, a plurality of catch block

More than 2.1 in order to capture abnormal, you need to pay attention to unusual order problems, the parent should be the last exception handling

More than 2.2 abnormal capture, which would only enter an exception

3.try catch block of statements is a separate

Use the second solution under normal circumstances.

 

        try {
            
        }
        finally {
            
        }

try ... finally appear only runtime exceptions when the wording
to emphasize the statements inside finally have to run


 

Abnormal, will prompt an error during compilation compile-time, we have to try catch the forced exception.

When in addition RuntimeException, other direct inheritance Exception subclass are compiled abnormal

Guess you like

Origin www.cnblogs.com/liqking/p/11973815.html