Retrofitting Code Using LLMs to Support Exceptional Behavior
Not on the map. Why?
Abstract (arXiv)
Exception Related Code (ERC), which includes throw statements, conditions (if statements) that guard those throw statements, and try/catch blocks, is an essential component of software systems, allowing developers to detect and handle exceptional states that deviate from the expected program behavior. However, manually writing ERC across large codebases is tedious. We propose a novel task: retrofitting existing code with ERC. Namely, given code (without ERC) and Exceptional Behavior Tests (EBTs) (e.g., check if method throws InvalidArgumentException if null is given as the value to the argument) we aim to automatically generate missing ERC, such that the given tests pass. We design and implement Exception Coder (EXCODER) that performs context engineering to help Large Language Models (LLMs) tackle this task. EXCODER integrates static and dynamic program analysis with LLMs by providing the extracted contextual information to the LLMs. To evaluate EXCODER, we build a benchmark constructed from GitHub Java repositories, where we systematically remove ERC in 304 methods from 75 projects. Our results demonstrate that EXCODER provides an effective, though imperfect, solution to this problem in automated code generation, offering developers the first way to implement ERC following test-driven development. When combined with Qwen 2.5 Coder 32b, EXCODER achieves pass@1, 5, and 10 rates of 85.92% (12.56 percentage points over baseline), 86.18% (12.82 p.p. over baseline), and 86.51% (13.15 p.p. over baseline), respectively, on developer-written test suites. Our manual inspection of the generated code further reveals limitations of EXCODER, pointing to directions for future work.
Key facts. No citing papers in the map yet (data through 14 Oct 2026). Builds on 22 of its 39 references that are in the map. First posted on arXiv 9 Sep 2026.
Builds on
22 of 39 references.
References · 22
- 2017Attention Is All You Needcited by 60,361
- 2020Language Models are Few-Shot Learnerscited by 32,419
- 2024The Llama 3 Herd of Modelscited by 14,715
- 2021Evaluating Large Language Models Trained on Codecited by 8,320
- 2023Reflexion: Language Agents with Verbal Reinforcement Learningcited by 4,276
- 2023Code Llama: Open Foundation Models for Codecited by 2,139
- 2022Competition-Level Code Generation with AlphaCodecited by 1,462
- 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,310
- 2024Qwen2.5-Coder Technical Reportcited by 1,203
- 2024Phi-4 Technical Reportcited by 711
- 2019CodeSearchNet Challenge: Evaluating the State of Semantic Code Searchcited by 654
- 2022CodeRL: Mastering Code Generation through Pretrained Models and Deep Reinforcement Learningcited by 358
10 more
- 2024CodeAgent: Enhancing Code Generation with Tool-Integrated Agent Systems for Real-World Repo-level Coding Challengescited by 282
- 2024AutoCodeRover: Autonomous Program Improvementcited by 278
- 2023Is Self-Repair a Silver Bullet for Code Generation?cited by 197
- 2024Test-Driven Development for Code Generationcited by 34
- 2023Learning Deep Semantics for Test Completioncited by 31
- 2023CAT-LM: Training Language Models on Aligned Code And Testscited by 28
- 2023From Misuse to Mastery: Enhancing Code Generation with Knowledge-Driven AI Chainingcited by 15
- 2024Towards Agentic Runtime Healingcited by 7
- 2025LLMs Lean on Priors, Not Programming Language Semanticscited by 6
- 2024exLong: Generating Exceptional Behavior Tests with Large Language Modelscited by 4
Built on by
Not cited yet.