Java Nested try catch block unreachable issues -
here part of code...when want compile shows unreachable catch block selfdefineexception. exception never thrown try statement body
how can fix it, can me, cuz have tried million times solve
try { statement 1; statement 1; statement 1; statement 1; try { statement 3; } catch (selfdefineexception er) { string error = er.getmessage(); system.out.print("issue: \n\t(" +er.getmessage() + ")"); result = false; } } } catch (selfdefineexception er) { system.out.print("failed: " + er.getmessage()); }
if selfdefineexception checked exception (which is, unless extending runtimeexception), should catch or declare (http://docs.oracle.com/javase/tutorial/essential/exceptions/catchordeclare.html). there 3 possible scenarios may give "unreachable code" here:
- if statement 3 1 calls method throws selfdefineexception, second catch unreachable, statements above can't throw that.
- if statement 3 doesn't contain call method throws selfdefineexception, first catch unreachable.
- if none contain calls methods declare "throws selfdefineexception" in method definition, both catch blocks unreachable.
Comments
Post a Comment