Why does the code execution never enter the catch block (java)?

Try changing your method to try { isSuccess = insertUserData(st, blocks, db, actor); system.out. Print("after insertUserData"); } catch (Exception e) { System.out. Print("before throwing"); throw new ImportException("Could not insert user on line " + rowCounter); } so that you can make sure that what you see in debug is what actually being executed (by checking your console), and whether insertUserData actually throws an exception or not.

Thanks, this led me to the solution. – simon May 5 '09 at 9:04.

If "test2" is printed, then there is no exception at all being thrown by importUsers(). The line information in the debugger can be inaccurate. Try putting a breakpoint in the constructor of the Exception to see if it's really being created.

It would help if that method was included in your question as well...

It does. I mentioned that "I can see in the debugger that the throw clause is executed"; more specifically, I see in debugger that the code on line throw new ImportException("Could not insert user on line " + rowCounter); is executed. – simon May 5 '09 at 8:47 I didn't add the code from the insertUserData method, because the actual exception is thrown several levels deep, it would be complicated to follow.

– simon May 5 '09 at 8:49.

Seeing the debugger step to a line with a "throw" does not mean that something is thrown, as the line information is not always completely accurate.

Check the following, by order: check that your breakpoints are synchronized with the source code insertUserData() is not throwing an exception at all, verify if, at all, it should be throwing an exception or not. Looks like you are expecting something that never comes. Check that ImportException is indeed the same object in both cases you refer to it.

If the output is "test2" then certainly the exception was not thrown. Just guessing ... Sometimes your IDE may not be synchronized with the source code that is actually executing, specially if your code is part of an external library... If you change the library's code and don't update the actual classpath, or if that change happens while debugging, the lines of code may change and you may be seeing the exception to be thrown although that isn't really happening.

Problem solved. It appears that the try-catch block in method importUsers was surrounded by another try-catch block, which did not throw the ImportException. So the first catch block was working correctly, I just missed the second one.

Try to catch a Throwable, the root of Exception and Error, with: try{ av = UserHelper. ImportUsers(data, admin); System.out. Print("test2"); } catch (ImportException ie) { System.out.

Print("testE"); returnMessageValue = ie.getMessage(); } catch (Exception e) { System.out. Print("testE2"); } catch (Throwable t) { // Here you'll catch *anything* else System.out. Print("testTE"); }.

Generally you should only catch the exceptions that are relevant to the level that you're at, so be weary of long catch chains. That being said sometimes this very scenario is thrust upon us... – CurtainDog May 5 '09 at 9:20.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions