[)roi(]
Executive Member
- Joined
- Apr 15, 2005
- Messages
- 6,282
Interesting study of ineffective exception handling.
Result:
Conclusion:
In practice I've rarely found many valid uses of this pattern; and in practice it's a far worse code smell than partial functions; because it can be used to expressively mask problems, whereas at least the preconditions usually associated with partial functions, have a clearly defined set of failures (they're a better kind of bad
)
In studying language design, it's obvious that exception handling cannot be avoided, but it's also (at least for me), obvious that current implementations in languages like Java, C#, ... have made it too easy to simply ignore all exceptions, and even some IDEs actively help you to add the superfluous "try catch block". Consider for a moment how much bad code relies on exception avoidance to appear stable?
As to alternatives: many lower level exceptions should simply be rethrown and be dealt with higher up the call stack; but it should ultimately be dealt with and never ignored; because any API with exceptions that you can safely ignore shouldn't have had exceptions in the first place i.e. they were probably a partial function masquerading as an exception.
Link to study
http://plg.uwaterloo.ca/~migod/846/current/projects/09-NakshatriHegdeThandra-report.pdf
Java is one of the few programming languages to enforce an additional compilation check on certain sub- classes of the Exception class through Checked Exceptions. This enforcement has made the writing of exception handling code very common. Almost all the existing IDEs today give the suggestions and even generate the try-catch code automatically to assist the developers. This motivated us to study the habits of developers in general. As part of this study, empirical data was extracted from software projects developed in Java
Result:
Conclusion:
I've never been able to appreciate the thinking behind languages that by design chose to enforce "try catch blocks" patterns.In this paper, we studied all Java projects in the GitHub and SourceForge repositories to spot common exception handling practices. We have particularly analyzed the checked exception handling in good detail. Next, these observations were compared against best practices presented by Bloch (book - “Eective Java”). To sum up the results, most developers ignore checked exceptions and leave them unattended. This is true for other types of exceptions as well. General exception handling shows developer inclination shifting from proactive recovery to debugging.
The ignore-for-now and mere logging approach followed for checked exceptions may help with debugging, but the absence of required recovery steps and continued smooth flow may lead to errors going unnoticed and potential in- correct product output. Thus, handling exceptions well is a skill that developers need to inculcate in themselves, else this language enforcement of checked exception handling will fall short of its intended value. Developers also tend to use generic handlers over specific ones. The reason for these approaches cannot be confirmed to be correct or incorrect without studying source codes. However overall, the results show major di↵erences between theoretical best practices and the use of exception handling in practice. We further summarized the best practices stated by Bloch and described one of the recommended approaches by Bruce to tackle exceptions.
In practice I've rarely found many valid uses of this pattern; and in practice it's a far worse code smell than partial functions; because it can be used to expressively mask problems, whereas at least the preconditions usually associated with partial functions, have a clearly defined set of failures (they're a better kind of bad
In studying language design, it's obvious that exception handling cannot be avoided, but it's also (at least for me), obvious that current implementations in languages like Java, C#, ... have made it too easy to simply ignore all exceptions, and even some IDEs actively help you to add the superfluous "try catch block". Consider for a moment how much bad code relies on exception avoidance to appear stable?
As to alternatives: many lower level exceptions should simply be rethrown and be dealt with higher up the call stack; but it should ultimately be dealt with and never ignored; because any API with exceptions that you can safely ignore shouldn't have had exceptions in the first place i.e. they were probably a partial function masquerading as an exception.
Link to study
http://plg.uwaterloo.ca/~migod/846/current/projects/09-NakshatriHegdeThandra-report.pdf
Last edited: