Thank you everyone for contributing to the discussion to date. There have been quite a number of good points made, I think. I'm still working through the implications of all the ideas.
aassddff
@aassddff
Best posts made by aassddff
Latest posts made by aassddff
-
RE: Try-catch style
-
Try-catch style
Good day
I'm looking for some guidance and/or opinions regarding good style when using try-catch blocks. When (as is more often than not the case) the statement that may throw the exception is followed by other statements to be executed if and only if said exception is not thrown, I see a lot of this pattern:
try {
//statement that may throw exception here
}
catch(Exception e) {
//statements to deal with failure here
return;
}
//statements to be executed if and only if exception is not thrown here
Particularly when there are multiple instances of this pattern in a method nested at various levels I'm not comfortable with the proliferation of exit points because it means that I can't trace an execution path through the method simply by reading branching/looping conditions and observing braces and indents - I now have to check every block for return statements. Is it just me who has a problem with this? Unfortunately all the alternatives I can think of are worse. Any ideas?
Regards
me