Is it valid to have finally block without try and catch?

前端 未结 11 1582
遇见更好的自我
遇见更好的自我 2021-02-04 01:32

I am trying to use the finally block without using the try/catch blocks but getting the error in Eclipse.

Can I use the finally block without using the try/catch blocks?

11条回答
  •  悲哀的现实
    2021-02-04 02:00

    • A try statement should have either catch block or finally block, it can have both blocks.

    • We can’t write any code between try-catch-finally block.

    • We can’t have catch or finally clause without a try statement.

    • We can have multiple catch blocks with a single try statement.try-catch blocks can be nested similar to if-else statements.

    • We can have only one finally block with a try-catch statement.

提交回复
热议问题