Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9040299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T09:57:15+00:00 2026-06-16T09:57:15+00:00

Is there a way to ‘detect’ what exceptions function/method raises? Examplifying: def foo(): print

  • 0

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.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T09:57:16+00:00Added an answer on June 16, 2026 at 9:57 am

    You can’t reasonably do this with Python, for a few reasons:

    1) The Python primitives don’t document precisely what exceptions they can throw. The Python ethos is that anything can throw any exception at any time.

    2) Python’s dynamic nature makes it very difficult to statically analyze code at all, it’s pretty much impossible to know what code “might” do.

    3) All sorts of uninteresting exceptions would have to be in the list, for example, if you have self.foo, then it could raise AttributeError. It would take a very sophisticated analyzer to figure out that foo must exist.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there way to spread out elements, (eg: < li>'s inside a < ul>)?
Is there way to spread out elements, (eg: <li>'s inside a <ul>), within a
Is there way to add new method to List object over the object from
Is there way to configure the objects from inside the code rather than configuring
Is there way to print from Apple and Android mobile browsers via bluetooth. I
Is there way to create embedded HSQLDB inside my web-app directory (I want that
Is there way to capture and print out all of the requests and responses
Is there way in next piece of code to only get the first record?
Is there way to bind a method interceptor to a provider rather than an
Is there way to associate a javascript function to a user control? Lets say

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.