Which Exception Shall We Throw?
Hao Zhong
摘要
With the support of exception handling mechanisms, when an error occurs, its corresponding typed exception can be thrown. A thrown exception can be caught and the handling code will resolve the error (e.g., closing resources), if the type of the thrown exception matches the type of the expected exceptions. Although this 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 automatically predict its best exception(s). We have evaluated ThEx on 12,012 thrown exceptions that were collected from nine popular open-source projects. Our results show that it can achieve high f-scores and mcc values (both around 0.8). On this benchmark, we also evaluated the impacts of our underlying technical details. Furthermore, we evaluated our approach in the wild, and used ThEx to detect anomalies from the latest versions of the nine projects. In this way, we found 20 anomalies, and reported them as bugs to their issue trackers. Among them, 18 were confirmed, and 13 have already been fixed.
问问这篇 Paper
智能体会读完全文。
Lune 把这篇 Paper 索引到了每一个公式,引用它的顶会 Paper 也一样。你提问,回答直接引用原文。
引用它的顶会 Paper3
- exLong: Generating Exceptional Behavior Tests with Large Language ModelsJiyang Zhang, Yu Liu, Pengyu Nie, Junyi Jessy Li 等ICSE 2025 · 被引用 2 次
- Cut to the Chase: An Error-Oriented Approach to Detect Error-Handling BugsHaoran Liu, Zhouyang Jia, Shanshan Li, Yan Lei 等FSE 2024 · 被引用 1 次
- Error Delayed Is Not Error Handled: Understanding and Fixing Propagated Error-Handling BugsHaoran Liu, Shan-shan Li, Zhouyang Jia, Yuanliang Zhang 等FSE 2025
它引用的顶会 Paper2
相关 Paper
- Learning to Handle ExceptionsJian Zhang, Xu Wang, Hongyu Zhang, Hailong Sun 等ASE 2020 · 被引用 19 次
- Programming Assistant for Exception Handling with CodeBERTYuchen Cai, Aashish Yadavally, Abhishek Mishra, Genesis Montejo 等ICSE 2024 · 被引用 4 次
- BERT-Based Code Learning for Exception Localization and Type PredictionChongyu Zhang, Qiping Tao, Liangyu Chen, Min ZhangAAAI 2025 · 被引用 1 次
- Detecting Exception Handling Bugs in C++ ProgramsHao Zhang, Ji Luo, Mengze Hu, Jun Yan 等ICSE 2023 · 被引用 7 次
- Reducing Bug Triaging Confusion by Learning from Mistakes with a Bug Tossing Knowledge GraphYanqi Su, Zhenchang Xing, Xin Peng, Xin Xia 等ASE 2021 · 被引用 19 次
