BERT-Based Code Learning for Exception Localization and Type Prediction

Abstract

Exception handling is crucial but challenging in program development. It needs to identify and handle all potential exceptions within programs to ensure system security and stabilization. Traditional exception handling relies on the expertise and experience of programmers, which often leads to oversights. Therefore, identifying exceptional code and recommending handling solutions are hot research topics with significant practical value. This paper presents a model called CodeHunter for exception localization and type prediction. The model first utilizes BERT-based model to represent code features and then uses Bi-LSTM for sequence labeling to pinpoint exceptional code. Additionally, this model also considers contextual features of the exception code and learns weights for the code within the try block and its context through the self-attention mechanism. Subsequently, it performs exception localization and predicts exception types. We conduct experiments on three different datasets. The results demonstrate that in the task of exception localization, our model can achieve a maximum accuracy of 98.6%, exceeding SOTA baselines by 11.2%. In the task of exception type prediction, our model can surpass the accuracy of SOTA baselines by a maximum of 18.7%, achieving 92.0% Top-1 accuracy. The rationality of techniques used in our model is also proved by the ablation testing. The model is implemented as an IDE plugin for programming convenience.

Cite

Text

Zhang et al. "BERT-Based Code Learning for Exception Localization and Type Prediction." AAAI Conference on Artificial Intelligence, 2025. doi:10.1609/AAAI.V39I1.32090

Markdown

[Zhang et al. "BERT-Based Code Learning for Exception Localization and Type Prediction." AAAI Conference on Artificial Intelligence, 2025.](https://mlanthology.org/aaai/2025/zhang2025aaai-bert/) doi:10.1609/AAAI.V39I1.32090

BibTeX

@inproceedings{zhang2025aaai-bert,
  title     = {{BERT-Based Code Learning for Exception Localization and Type Prediction}},
  author    = {Zhang, Chongyu and Tao, Qiping and Chen, Liangyu and Zhang, Min},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year      = {2025},
  pages     = {1040-1047},
  doi       = {10.1609/AAAI.V39I1.32090},
  url       = {https://mlanthology.org/aaai/2025/zhang2025aaai-bert/}
}