Is final always executed in the try catch phrase?

Asked 1 years ago, Updated 1 years ago, 125 views

    try {  
        something();  
        return success;  
    }  
    catch (Exception e) {   
        return failure;  
    }  
    finally {  
        System.out.println("i don't know if this will get printed out.");
    }

Even if I return in try and catch in this code, is it finally executed??

java return try-catch-finally finally

2022-09-22 22:38

1 Answers

Yes, it does. If "finally" doesn't work, This is the case when the JVM explodes when System.exit() is called or when another thread is interfering.


2022-09-22 22:38

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.