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 9009879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T02:18:54+00:00 2026-06-16T02:18:54+00:00

I have a code sample below, where I want to catch some exception: in

  • 0

I have a code sample below, where I want to catch some exception:

in the main function:

try:
    ...
    do_something()
except some_exception,e:
    do_some_other_thing

in the do_something function

try:
    ...
except some_exception,e:
    do_some_other_thing

So when I was testing it, I noticed that the exception was handled twice (once in do_somthing(), and once in the main function), is my observation accurate?

Is there a way to catch the exception that are only not captured by its function? Because there are two scenarios that I want to catch and they are somewhat wrapped into the same exception handling class(i.e. some_exception)

  • 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-16T02:18:55+00:00Added an answer on June 16, 2026 at 2:18 am

    Your observation is inaccurate; there must be 2 places that raise some_exeption, or you are explicitly re-raising it.

    Once an exception has correctly been caught, it will not be caught by other handlers higher up in the stack.

    This is easiest shown with a little demonstration:

    >>> try:
    ...     try:
    ...         raise AttributeError('foo')
    ...     except AttributeError as e:
    ...         print 'caught', e
    ... except AttributeError as e:
    ...     print 'caught the same exception again?', e
    ... 
    caught foo
    

    Only the inner except handler was invoked. If, on the other hand, we re-raise the exception, you’ll see both handlers print a message:

    >>> try:
    ...     try:
    ...         raise AttributeError('foo')
    ...     except AttributeError as e:
    ...         print 'caught', e
    ...         raise e
    ... except AttributeError as e:
    ...     print 'caught the same exception again?', e
    ... 
    caught foo
    caught the same exception again? foo
    

    As such, there is no need to have to handle ‘exceptions that are not caught by the function’; you will only need to handle exceptions that were not already caught earlier.

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

Sidebar

Related Questions

I have some code for validating date below: function validateForm() { var errFound =
I have written grammar for a language (sample code below) //this is a procedure
I have a plot (sample code pasted below) that I am trying to add
I have the below sample code for a navigation list: <div id=menu> <ul> <li><a
I have some code that I want to build. The code uses boost::ptr_map class
Below is sample code from a Module I have in my Flex app. I
I am using XSLT 1.0 and have below sample code: In my XSLT, I
I have got below code sample with me where I am able to read
I have a sample code snippet below which works just fine (I trimmed the
Below is the code that I have written. I want to do the simple

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.