Java Finally Block
Java Finally Block
Java Finally Block
Let's see the different cases where java finally block can be used.
Case 1
Let's see the java finally example where exception doesn't occur.
class
TestFinallyBlock{
Test it Now
Output:5
finally block is always executed
rest of the code...
Case 2
Let's see the java finally example where exception occurs and not
handled.
class
TestFinallyBlock1{
Test it Now
Case 3
Let's see the java finally example where exception occurs and handled.
public class
TestFinallyBlock2{
Test it Now
Rule: For each try block there can be zero or more catch blocks, but
only one finally block.
https://www.javatpoint.com/finally-block-in-exception-handling 2/3
1/31/2020 Java Finally block - javatpoint
← prev next →
https://www.javatpoint.com/finally-block-in-exception-handling 3/3