How do we account for exception throws in static code analysis?

Viewed 273

I wrote an utility to create a CFG (Control Flow Graph) for a java method whose nodes are basic blocks instead of instructions.

I could not consider exception throws to be edges in CFG. The reasons are that:

  1. Every instruction in try block can potentially throw exceptions / errors which can be handled by any of the nesting try-catch blocks. If we consider exception throws as edges, the number of paths to process increases drastically, and so will the number of nodes in CFG.
  2. We need to know the inheritance hierarchy for exceptions before we can decide what jumps are possible.

How do static code analyzers solve this problem?

I am stuck at this point. If I have to proceed, how should I go about it?

Edit: in my case, I can limit support to those use cases which can specify where and which exceptions are thrown. This solved my second problem. I would still like to know how generic static code analysers manage this.

1 Answers
Related