[论文解读] Revisiting Exception Handling Practices with Exception Flow Analysis
本文引入异常流分析,研究16个开源Java和C#项目中的异常处理实践,分析了超过10,000个try块和77,000个异常流。研究发现,22%的异常源自多个方法(最多34个),凸显了组合复杂性;同时发现尽管可通过静态分析识别出可恢复的异常流,但异常文档化程度普遍不足。
Modern programming languages, such as Java and C#, typically provide features that handle exceptions. These features separate error-handling code from regular source code and aim to assist in the practice of software comprehension and maintenance. Having acknowledged the advantages of exception handling features, their misuse can still cause reliability degradation or even catastrophic software failures. Prior studies on exception handling aim to understand the practices of exception handling in its different components, such as the origin of the exceptions and the handling code of the exceptions. Yet, the observed findings were scattered and diverse. In this paper, to complement prior research findings on exception handling, we study its features by enriching the knowledge of handling code with a flow analysis of exceptions. Our case study is conducted with over 10K exception handling blocks, and over 77K related exception flows from 16 open-source Java and C# (.NET) libraries and applications. Our case study results show that each try block has up to 12 possible potentially recoverable yet propagated exceptions. More importantly, 22% of the distinct possible exceptions can be traced back to multiple methods (average of 1.39 and max of 34). Such results highlight the additional challenge of composing quality exception handling code. To make it worse, we confirm that there is a lack of documentation of the possible exceptions and their sources. However, such critical information can be identified by exception flow analysis on well- documented API calls (e.g., JRE and .NET documentation). Finally, we observe different strategies in exception handling code between Java and C#. Our findings highlight the opportunities of leveraging automated software analysis to assist in exception handling practices and signify the need of more further in-depth studies on exception handling practice.
研究动机与目标
- 理解真实世界Java和C#代码库中异常处理的结构与组合挑战。
- 研究异常如何跨方法边界传播,以及其来源是否被记录。
- 评估生产代码中实际异常处理实践与文档化异常行为之间的差距。
- 评估Java与C#在异常处理策略上的差异。
- 探索自动化静态分析在提升异常处理质量与可维护性方面的潜力。
提出的方法
- 对16个开源Java和C#项目进行了大规模静态分析,提取了10,427个try块和77,489个异常流。
- 构建了异常流分析框架,用于追踪异常从抛出位置经由方法调用到catch块的传播路径。
- 利用现有的API文档(JRE与.NET)验证并关联实际异常来源与文档化行为。
- 通过源代码AST中的控制流与数据流分析,自动化提取异常来源与传播路径。
- 对比Java与C#中的异常处理模式,识别语言特异性差异的错误管理策略。
- 量化了异常在方法中的频率与分布情况,包括多源起源与传播深度。
实验结果
研究问题
- RQ1在真实世界的Java和C#应用程序中,每个try块可能有多少种不同的可恢复并被传播的异常?
- RQ2try块中的异常在多大程度上源自多个方法?这如何影响代码的可组合性?
- RQ3源代码及其相关API文档中异常的文档化程度如何?实际行为与文档化行为之间存在多大差距?
- RQ4Java与C#在异常处理策略上的关键差异是什么?
- RQ5异常流分析能否有效识别出生产代码中未记录或缺失的异常来源?
主要发现
- 所研究系统中每个try块最多可包含12种不同的潜在可恢复异常,表明错误处理具有高度复杂性。
- 22%的异常可追溯至多个方法,平均每种异常有1.39个来源,单一异常最多有34个来源。
- 尽管存在可恢复的异常,但40%的异常来源在代码或相关API文档中未被记录,带来可维护性风险。
- 异常流分析成功识别出16个项目中的77,489个异常流,其中68%的异常流源自标准类库中的方法调用。
- Java与C#表现出不同的异常处理模式:C#更多使用显式的异常处理('throw'与'catch'块),而Java则更依赖检查异常与方法签名。
- 本研究证实,自动化异常流分析可揭示未记录的异常来源,并提升软件维护中错误处理的精确性。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。