Get the App
SLTechnology News&Howtos  ›  Development  › 

What is the limited range of finally statement blocks?

Shulou Source: shulou.com Published: 2022-06-02 04:45:04 10月19日 Update

This article mainly explains "what is the limited scope of finally sentence blocks". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the limited scope of finally sentence blocks".

Does the finally statement block have to be executed?

The answer is not necessarily.

Returns directly to the block of finally statements that are not executed

Throwing exception is not executed to finally statement block

System exit not executed to finally statement block

...

There are many special cases that cause finally statement blocks not to be executed.

The code is as follows

Public static String test () {

String str = null

Int I = 0

If (I = = 0) {

Return str;// directly returns unexecuted to finally statement block

}

Try {

System.out.println ("try...")

Return str

} finally {

System.out.println ("finally...")

}

}

Public static String test2 () {

String str = null

Int I = 0

I = I / 0ram / throw exception not executed to finally statement block

Try {

System.out.println ("try...")

Return str

} finally {

System.out.println ("finally...")

}

}

Public static String test3 () {

String str = null

Try {

System.out.println ("try...")

System.exit (0); / / system exit not executed to finally statement block

Return str

} finally {

System.out.println ("finally...")

}

}

Thank you for your reading, the above is the content of "what is the limited scope of finally sentence blocks". After the study of this article, I believe you have a deeper understanding of what the limited scope of finally sentence blocks is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Sentences limited scope learning content situation system special code that is ideas articles more knowledge knowledge points answers articles follow questions practice Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Tech Info macOS MariaDB Huawei