I have built a simple test routine to play around with exceptions and how they work:
private static void testExceptions(int i)
{
try
{
if (i==1 || i==2) System.out.println(1/0);
if (i==3 || i==4) throw new UnsupportedOperationException("Not yet implemented");
}
catch (UnsupportedOperationException e)
{
e.printStackTrace();
}
finally
{
System.out.println("Always called - if errors occur or not.");
//next statement causes exception to be cleared
//(no error/exception reported to caller!)
if (i==1 || i==3) return;
}
}
Before I call that method I do some output with System.out.println("...");
Then I call testExceptions(3);
When I run this I get different output, e.g.:
Starting program...
System temp folder: F:\Temp
java.lang.UnsupportedOperationException: Not yet implemented
at at.mwildam.testprj.Main.testExceptions(Main.java:442)
User name: mwildam
at at.mwildam.testprj.Main.main(Main.java:173)
User home dir: C:\Dokumente und Einstellungen\myuserid
App language: de
Starting tests...
Always called - if errors occur or not.
Tests finished.
How can this be? - The expected output would be in my opinion:
Starting program...
System temp folder: F:\Temp
User name: mwildam
User home dir: C:\Dokumente und Einstellungen\myuserid
App language: de
Starting tests...
java.lang.UnsupportedOperationException: Not yet implemented
at at.mwildam.testprj.Main.testExceptions(Main.java:442)
at at.mwildam.testprj.Main.main(Main.java:173)
Always called - if errors occur or not.
Tests finished.
And actually when running this from the commandline (not in the IDE) then that is exactly the output - as expected. What goes wrong here?