arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2601.01271cs.SE
收藏

CatchAll: 基于知识引导的LLM仓库感知异常处理

CatchAll: Repository-Aware Exception Handling with Knowledge-Guided LLMs

School of Computer Science, Shanghai Jiao Tong University(上海交通大学计算机科学技术学院)

Qingxiao Tao, Xiaodong Gu, Hao Zhong, Beijun Shen

AI总结:

CatchAll通过引入三种互补的异常处理知识层,提升LLM在仓库级别异常处理的准确性与上下文感知能力。

摘要:

异常处理是许多编程语言中至关重要的向前错误恢复机制,使开发人员能够通过结构化构造(例如try-catch块)来管理运行时异常。不当或缺失的异常处理往往会导致严重后果,包括系统崩溃和资源泄漏。尽管大型语言模型(LLMs)在代码生成方面表现出强大的能力,但它们在仓库级别处理异常时面临困难,这归因于复杂的依赖关系和上下文约束。在本工作中,我们提出了CatchAll,一种新的基于LLM的仓库感知异常处理方法。CatchAll为LLM配备了三种互补的异常处理知识层:(1)API级别的异常知识,来源于一个经验性构建的API-异常映射,该映射描述了现实世界代码库中API的异常抛出行为;(2)仓库级别的执行上下文,通过建模围绕目标代码的上下文调用轨迹来捕捉异常传播;(3)跨仓库的处理知识,源自从历史代码中挖掘出的可重用异常处理模式。这些知识被编码到结构化提示中,以指导LLM生成准确且上下文感知的异常处理代码。为了评估CatchAll,我们构建了两个新的仓库感知异常处理基准:大规模数据集RepoExEval和可执行子集RepoExEval-Exec。实验表明,RepoExEval在仓库级别异常处理方面持续优于最先进的基线,实现了CodeBLEU得分为0.31(对比最佳基线的0.27%),意图预测准确率为60.1%(对比48.0%),Pass@1为29%(对比25%)。这些结果证实了RepoExEval在现实世界仓库级别异常处理中的有效性。

英文摘要:

Exception handling is a vital forward error-recovery mechanism in many programming languages, enabling developers to manage runtime anomalies through structured constructs (e.g., try-catch blocks). Improper or missing exception handling often leads to severe consequences, including system crashes and resource leaks. While large language models (LLMs) have demonstrated strong capabilities in code generation, they struggle with exception handling at the repository level, due to complex dependencies and contextual constraints. In this work, we propose CatchAll, a novel LLM-based approach for repository-aware exception handling. CatchAll equips LLMs with three complementary layers of exception-handling knowledge: (1) API-level exception knowledge, obtained from an empirically constructed API-exception mapping that characterizes the exception-throwing behaviors of APIs in real-world codebases; (2) repository-level execution context, which captures exception propagation by modeling contextual call traces around the target code; and (3) cross-repository handling knowledge, distilled from reusable exception-handling patterns mined from historical code across projects. The knowledge is encoded into structured prompts to guide the LLM in generating accurate and context-aware exception-handling code. To evaluate CatchAll, we construct two new benchmarks for repository-aware exception handling: a large-scale dataset RepoExEval and an executable subset RepoExEval-Exec. Experiments demonstrate that RepoExEval consistently outperforms state-of-the-art baselines, achieving a CodeBLEU score of 0.31 (vs. 0.27% for the best baseline), intent prediction accuracy of 60.1% (vs. 48.0%), and Pass@1 of 29% (vs. 25%). These results affirm RepoExEval's effectiveness in real-world repository-level exception handling.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑