Quantcast
Channel: Reza's Weblog
Viewing all articles
Browse latest Browse all 50

exit(0) over finally

$
0
0

I have always thought that finally blocks are executed in any circumstances; but that wasn't true!

public class Test {
    public static void main(String[] args) {      
        try {          
            System.out.println("Hi");           
            System.exit(0);       
        } finally {           
            System.out.println("Hi2");     
       }   
    }
}

In this case System.exit method halts the execution of the current thread. The presence of a finally clause does not give the thread special permission to continue executing.


Viewing all articles
Browse latest Browse all 50

Trending Articles