paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Which Exception Shall We Throw?

应当抛出哪个异常?
ASE Proceedings of the 37th IEEE/ACM International Conference on Automated Software Engineering2022匹配度 3/10 · 该论文将机器学习用于源代码上下文预测应抛出的异常,属于AI与程序语言/开发者工具交叉,但与用户核心关注的静态分析、Agentic程序、LLM改进静态分析/形式化验证、浮点程序分析及贝叶斯程序分析均无直接关联,也未使用LLM/Agent技术。引用 6 inbox
Hao Zhong
crossref: 2026-09-12

AI 速览

一句话:提出首个异常抛出推荐方法 ThEx,基于源码上下文学习分类模型预测应抛出的异常。

异常处理机制对解决运行时错误至关重要,但若抛出的异常本身不正确,后续捕获和处理便无法正确进行,并已导致真实严重缺陷。现有研究多关注捕获、处理异常及检测相关 bug,却没有方法推荐应抛出哪个异常。异常在程序中广泛使用,却常缺乏文档且含义模糊,不同项目团队的异常使用习惯也可能完全不同,因此即使经验丰富的程序员也难以判断该抛何异常。本文提出首个方法 ThEx,从源文件中已有的抛出异常学习分类模型,提取抛出位置、相关变量名等异常周围代码信息作为特征;给定新的编程上下文,ThEx 可预测其最合适的异常。

问题
抛出的异常若不正确,将导致异常无法被正确捕获和处理并引发严重 bug;但目前没有方法推荐应抛出哪个异常。
方法
ThEx 从源文件已有抛出异常中学习分类模型,使用抛出位置、相关变量名等上下文代码信息作为特征,为新上下文预测最合适的异常。
评估
摘要未给出具体实验评估或结果,仅提出并描述该预测方法。
原文摘要(Abstract)

Although the exception handling mechanism is critical for resolving runtime errors, bugs inside this process can have far-reaching impacts. Therefore, researchers have proposed various approaches to assist catching and handling such thrown exceptions and to detect corresponding bugs. If the thrown exceptions themselves are incorrect, their errors will never be correctly caught and handled. Like bugs in catching and handling exceptions, wrong thrown exceptions have caused real critical bugs. However, to the best of our knowledge, no approach has been proposed to recommend which exceptions shall be thrown. Exceptions are widely adopted in programs, often poorly documented, and sometimes ambiguous, making the rules of throwing correct exceptions rather complicated. A project team can leverage exceptions in a way totally different from other teams. As a result, even experienced programmers can have difficulties in determining which exception shall be thrown, although they have the skills to implement its surrounding code. In this paper, we propose the first approach, ThEx, to predict which exception(s) shall be thrown under a given programming context. The basic idea is to learn a classification model from existing thrown exceptions in source files. Here, the learning features are extracted from various code information surrounding the thrown exceptions, such as the thrown locations and related variable names. Then, given a new context, ThEx can predict its best exception(s).

链接与引用

DOI 原文 · PDF(开放获取) ·

BibTeX
@inproceedings{paperbot7245,
  title = {Which Exception Shall We Throw?},
  author = {Hao Zhong},
  booktitle = {ASE},
  year = {2022},
  doi = {10.1145/3551349.3556895}
}