If I have that many levels of nested ifs, I work at refactoring the method or wrapping a whole thing to a common exit point. I feel that either of those options are better than the unfollowable jumping around catch/finally blocks.
Doing what you are suggesting is also a sure-fire way of defeating compiler optimizations. On Jan 19, 10:29 am, DanH <[email protected]> wrote: > > The problem with the below code is that your MUST use a comment to > > understand what's going on. And that's the biggest problem with using > > exceptions as flow control logic -- unreadable code as you cannot scan > > the code top to bottom and understand its flow. You end up with a > > mess of a code with "finally" blocks peppered around to do clean up. > > And you shouldn't use comments anywhere else?? > > Oh, and one of the great things about using exceptions is that they > eliminate the unreadable control flow with all the "if (error) branch > around" logic. The size and intellectual complexity of a routine can > easily be reduced by a factor of 4-10 using exceptions vs return > codes, and the robustness of the code is greatly increased since the > "backout'" code is neatly nested vs being scattered about or all > gathered into one huddle and mysteriously managed with switches. > > On Jan 18, 6:39 pm, Zsolt Vasvari <[email protected]> wrote: > > > > > The problem with the below code is that your MUST use a comment to > > understand what's going on. And that's the biggest problem with using > > exceptions as flow control logic -- unreadable code as you cannot scan > > the code top to bottom and understand its flow. You end up with a > > mess of a code with "finally" blocks peppered around to do clean up. > > > I just don't see, from an API design point of view, why File.open() or > > Context.openInputFile() couldn't just return <null> if the file > > doesn't exist, instead of throwing an exception. Especially, since a > > file not existing is usually not an exception, but a common occurence. > > > On Jan 18, 11:52 pm, Paul <[email protected]> wrote: > > > > I agree, that would be by definition an exception state, where the > > > normal flow (check if file exists -> write to it) has been disrupted. > > > > I have a little file name generation routine that does make use of the > > > FileNotFoundException though, out of pure convenience: (pseudo-code) > > > > while (true) { > > > fileName = ... > > > try { > > > openFileInput(fileName); > > > } catch (FileNotFoundException e) { > > > // file doesn't exist, use this name > > > break; > > > } > > > > }- Hide quoted text - > > - Show quoted text - -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

