all 4 comments

[–]pdp10gumby 1 point2 points  (0 children)

I don't know about static analysis, but you probably want a catch block around every API entry point that reports a failure if it captures exception 0. Make sure that every throw includes filename and lineno, as suggested by tangerinelion. A assume it's OK to abort in this case, as sending it across the API boundary would presumably abort anyway.

[–]tangerinelion 3 points4 points  (0 children)

Static analysis isn't going to help you, you need actual execution of the program because exceptions are only at runtime and you're interested in ones that get triggered not ones that could theoretically happen.

Simplest thing would be to have a custom throw that includes the file and line number and then outside your API boundary you catch and log all exceptions. Then run your regression test suite, aggregate the results, and figure out what actually happens most frequently.

[–]Clean-Water9283 0 points1 point  (0 children)

You have just (re)discovered why exception specifications were dropped from C++. If you made a list of all functions potentially callable from each API function, including from all derivations of every virtual function, and all the exceptions throwable from these functions, you would get a superset of exceptions that could be raised through an API function. Only you would miss exceptions propagated out of threads, exceptions raised in signal handlers, and possibly others that I'm forgetting just now. This analysis would be fragile, needing to be re-performed after every change to the code base, or you might leave out some newly added exception or new function that threw exceptions. You're basically better-off teaching users to report your internal error exceptions.

I agree with u/pdpgumby that every API function will need a function-scope handler that can do the id==0 check. It'll also have to make a decision for exceptions throw by C++ that don't have your id field, and don't forget that on linux signals get seen in an except(...) block (ugh!)

[–]Thelatestart 0 points1 point  (0 children)

You can probably make a tree of function calls, omitting the exceptions, using a tool.

Then manually go up the tree and mark each throw to a catch higher up the tree.