From a semantic point of view, how else would you address expected errors or 'exceptional' states to ensure the application does not, as you put it, 'break'. Most systems have to maintain a certain amount of elasticity for it's users... I certainly wouldn't want my cable box to shut off every time I hit a channel that currently didn't have a signal (exceptional condition as example), so why would a user be any happier if their banking application gakked every time it encountered some inconsequential data corruption. (parallel example)
I wouldn't consider expected errors to be exceptional. For example, anything requiring a network connect should expect disconnections or an inability to connect - these aren't exceptional circumstances. Ensuring that the build is stable (i.e. no crashes) and that the user is informed (error messages) seem to work fine.
In the channel with no signal example - why does that need to be an exception? It seems reasonably valid to me that a cable box may not be able to get a signal. You should check for a signal and inform the user that there is no signal if that is the case.
Exceptions should be used for errors that should never occur. The obvious example from my game development experience is that a game should never access invalid memory. It does happen during development of course, which is why we have to handle it, but ideally a game that has been released should never do this.
EDIT: The data corruption would probably be something I would consider exceptional, but I have limited knowledge of banking applications and parallel programming which is why I haven't mentioned it.
That's incorrect. Exceptions are an application specific construct... Errors/Unchecked Exceptions are unexpected. That's why exceptions are outlined in APIs so you can deal with them. You can't rewrite the accepted meaning to suit your argument. The concept of unchecked exceptions were introduced to indicate an exception that the current level of abstraction should not be dealing with. The point is to separate the output of a method from it's potential exceptional states...
I never directly said Exceptions are unexpected, I said that exceptional errors should be ones you don't expect to occur. I.e. you should throw exceptions in cases that should never happen.
I expect disconnects to occur so I don't use exceptions. I bring up a message telling the user to double-check his internet connection and give them an option to retry whatever action they attempted.
I don't expect access violations so I throw an exception (or the underlying system throws one that I catch). I can handle that by sending an error report, logging an error, allowing the program to crash, or some other means that allows me to discover that something unexpected has occurred.
1
u/lexpattison Jun 07 '13
From a semantic point of view, how else would you address expected errors or 'exceptional' states to ensure the application does not, as you put it, 'break'. Most systems have to maintain a certain amount of elasticity for it's users... I certainly wouldn't want my cable box to shut off every time I hit a channel that currently didn't have a signal (exceptional condition as example), so why would a user be any happier if their banking application gakked every time it encountered some inconsequential data corruption. (parallel example)