Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • I made a few edits, worded the original Q poorly.. my question is more about how to keep the code clean while handling all the trying and catching and whatnot. It starts to feel very messy when try catch blocks are everywhere... Commented Mar 31, 2011 at 22:50
  • 1
    @Ed doesn't it bother you that your UI or Model is catching "SQLException"? To me, that's not very relevant. To each their own, I guess. Commented Mar 31, 2011 at 23:01
  • 1
    @Ed, that might be sort of OK in languages that don't have checked exceptions, but in languages with checked exceptions it's really ugly to have throws SQLException on a method that doesn't imply that SQL is even involved. And what happens if you decide that some operations should go to a file store? Now you have to declare throws SQLException, IOException, etc. It'll get out of hand. Commented Mar 31, 2011 at 23:23
  • 1
    @Ed to the end user SQLException does not mean much, especially so if your system can support multiple types of persistence apart from relational databases. As a gui programmer I'd much rather have to deal with DataNotFoundException than a whole set of low level exceptions. Very often an exception to a low level library is just part of normal life up above, in this case they are much easier to handle when their level of abstraction match the application's. Commented Apr 1, 2011 at 2:35
  • 1
    @Newtopian - I never said present the raw Exception to the end user. To end users, a simple 'Program has stopped working' message is enough whilst logging the Exception somewhere useful for support to pick up. In Debug mode it is useful to display the Exception. You shouldn't be caring about every possible Exception an API could throw unless you have a specific handler for such Exceptions; just let your Un-handled Exception catcher deal with it all. Commented Apr 1, 2011 at 8:06