Is there a way to 'detect' what exceptions function/method raises? Examplifying:
def foo():
print 'inside foo, next calling bar()'
_bar()
_baz()
# lots of other methods calls which raise other legitimate exceptions
def _bar():
raise my_exceptions.NotFound
def _baz():
raise my_exceptions.BadRequest
so, supposing that foo is part of my API and I need to document it, is there a way to get all exceptions that can be raised from it?
Just to be clear I don't want to handle those exceptions, they are supposed to happen (when a resource is not found or the request is malformed for instance).
I'm thinking to create some tool that transform that sequence of code in something 'inline' like:
def foo():
print 'inside foo, next calling bar()'
# what _bar() does
raise my_exceptions.NotFound
# what _baz() does
raise my_exceptions.BadRequest
# lots of other methods calls which raise other legitimate exceptions
Is there anything that can help me detect that instead of navigate through each method call? (Which goes deep into several files.)
raisestatement, and without attempting to descend / recurse into other methods or calls? Not exactly what you wished for but you would at least have a mapping from method names to possible exceptions, and that may be the main ones you're looking for? Not sure if that would be good enough without the call stack, but I imagine that might be an easier question to answer.