DetectThrowsException Decision Problem

Anoop Guragain, Duru Akbas, Joseph Oforkansi

September 8, 2025

Introduction

A simple exceptions “detection” program

  • Takes an input that is a string containing source code
  • Search through the source code line by line using regex for certain keys or pattern
  • Add those lines that matches to a list called “warnings” with a message
  • Convert that list into multi-line string and returns it

To be noted

  • It does not detect, it just kind of predicts if the program is going to throw an exception.
  • It does not run the program or confirms that an exception will or won’t occur.
  • It gives false positive and false negative such as it count comments and strings as the part of the source code

Exceptions

  • Divisible by zero
 if re.search(r"/\s*0", line):
    warnings.append(f"Division by zero at line {i}")
  • Value error (int() and float())
  if "int(" in line or "float(" in line:
    warnings.append(f"Possible ValueError in conversion at line {i}")
  • Index error
  if re.search(r"\w+\[.*\]", line):
    warnings.append(f"Possible IndexError/KeyError at line {i}")
  • Raise
  if "raise " in line:
    warnings.append(f"Explicit raise at line {i}")

Output

  • detect_exceptions function scans for risky patterns
  • Splits “code” into individual lines
  • Exception triggers are: division by zero, type conversions, indexing or dictionary access (opening and closing brackets and matches a word), explicit raise statements
  • Returns the warnings found

Conclusion

  • Heuristic detection: 🟢 Our DetectThrowsException program is a heuristic demonstration of a decision problem. It cannot prove whether an exception will occur, but it offers a first step by flagging suspicious patterns in source code.
  • Theoretical limits: ⚠️ This limitation connects to a fundamental idea in theoretical computer science: undecidability. Just as the halting problem shows no program can universally decide if another program will halt, no tool can perfectly predict all possible runtime exceptions
  • Practical Value: 💡 While imperfect, our detector shows how even a simple pattern-matching approach can still provide practical value in software development, helping catch likely errors early without guaranteeing complete correctness.

What Our Detector Can and Cannot Do

✅ Can Do ❌ Cannot Do
Detect simple patterns with regex (e.g., /0, int("abc"), raise) Prove with certainty that exceptions will (or won’t) occur
Flag likely sources of runtime errors early Account for user input, runtime values, or complex program logic
Provide a practical, lightweight heuristic Solve the general problem (undecidable, like the halting problem)

Key takeaway: A simple heuristic can still make a meaningful impact in software development, despite theoretical limits.

Thank You