I have created a code that would help me observe how exception handling works. I typed it all through Intellij IDEA, but it is not outputting in the way I wanted it to. The code looks like this:
public class JVMException {
public static void main(String[] args){
try{
faultyMethod();
} catch (OutOfMemoryError e){
//prints 1st
e.printStackTrace();
fixMemoryLeak();
}
}
public static void faultyMethod(){
throw new OutOfMemoryError("JVM is out of memory! Fix memory leak!");
}
public static void fixMemoryLeak(){
//prints 2nd
System.out.println("Fixing memory leak...");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
// prints 3rd
System.out.println("Done! The memory leak is fixed!");
}
}}
The output should print in the ordered that they were labeled, but I get this result instead:
When I run the same code in either Eclipse or browser IDEs like Repl.it, it prints out in the correct order. Is there some configuration in Intellij that I have to modify in order to get the correct output?
