Introduction
Exception handling features like try-catch-finally blocks are designed to improve software reliability by separating error-handling from standard logic. However, their misuse is a leading cause of catastrophic system failures and crashes. While software engineering researchers have identified various "anti-patterns"—problematic ways of coding exception logic—there has been a significant gap in understanding their prevalence in real-world software. This paper provides the first large-scale empirical study on the prevalence of exception handling anti-patterns across 16 major open-source Java and C# projects.
Methodology
The researchers performed an automated exception flow analysis to identify problematic patterns. Unlike simple text searches, the tool analyzed the flow of exceptions, collecting data from code syntax, third-party library documentation, explicit throw statements, and exception binding information. The study tracked 19 distinct anti-patterns categorized into three groups: Flow issues (e.g., Unhandled Exceptions), Handler issues (e.g., Catch Generic, Dummy Handler), and Throws issues (Java-specific).
Dataset Overview
The study analyzed 16 mature, high-activity open-source projects from GitHub, totaling over 1.5 million lines of code (KLOC) and nearly 10,000 catch blocks. The dataset includes a mix of applications and libraries to determine if project type influences coding practices.
Key Insights: The "Vital Few"
Out of 19 identified anti-patterns, only five are considered "prevalent," appearing in more than 20% of catch blocks or throw statements: Unhandled Exceptions, Catch Generic, Unreachable Handler, Over-catch, and Destructive Wrapping.
A major finding is that the programming language significantly influences developer behavior. While there was no statistically significant difference between "Applications" and "Libraries," the prevalence of specific anti-patterns varied drastically between Java and C#. This suggests that language features, such as Java's checked exceptions, shape developer behavior more than the intended use of the software.
Language-Specific Trends
The study highlights how language constraints drive specific bad habits:
- Destructive Wrapping: Java developers are nearly 18 times more likely to engage in Destructive Wrapping (catching an exception and throwing a new one without the original cause). The median prevalence in Java was 31.6%, compared to just 1.8% in C#. This is likely due to the Java compiler forcing developers to handle or declare checked exceptions, leading them to "wrap" exceptions just to satisfy the compiler.
- Catch Generic: Conversely, C# projects showed a much higher prevalence of Catch Generic (catching the base
Exceptionclass), with a median of 74.3% compared to 17.6% in Java.
Conclusion
Every project studied contained exception handling anti-patterns, with Unhandled Exceptions remaining the most widely detected issue. One problematic catch block can often hide dozens of different potential error types, acting as an "impact multiplier" for system instability. Future research should expand this analysis to dynamic languages and investigate the underlying developer intent behind these common bad practices.
Summary updated