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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:04:15+00:00 2026-05-16T16:04:15+00:00

I encountered a very strange behavior in Python, a behavior that is not consistent.

  • 0

I encountered a very strange behavior in Python, a behavior that is not consistent.

...
except IOError as msg:
    sys.exit("###ERROR IOError: %s" % (msg))

Usually this would get me a message like:

###ERROR IOError: [Errno 13] Permission denied: 'filename'

In same cases the above code is giving me a tuple instead of a proper error message.

###ERROR IOError: (13, 'Permission denied')

This is very strange because in all case the exception come from the same python method, codecs.open(...)

What makes me wonder more about this is that if I remove the handling the exception will reach upper levels with the right text (full error message), always!

except IOError as msg:
    print(msg)
    raise msg

The above example will always print a complete message, like IOError: [Errno 13] Permission denied: u'filename'.

Why is this happening and how do I prevent this, I don’t want to give incomplete error messages to the users.

I wanted to reproduce this behavior in a test file, but I was not able to reproduce this outside the project.

I suspect that is has something to do with the usage of sys.exit() because print(msg) will give good result but sys.exit not.

  • 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-05-16T16:04:16+00:00Added an answer on May 16, 2026 at 4:04 pm

    First, when reraising an exception, never do except Exc as e: raise e. It is always just plain raise with no arguments. This will preserve the traceback.

    No, this has nothing to do with sys.exit and everything to do with how the exception was instantiated. You are always getting an exception; just sometimes its string representation will resemble that of a tuple.

    >>> print IOError(13, 'Permission denied')
    [Errno 13] Permission denied
    >>> print IOError((13, 'Permission denied'))
    (13, 'Permission denied')
    

    Without showing the full traceback, there’s no way to tell what exactly is raising the error in this way. Also, without properly reraising like I pointed out, you won’t be getting the full traceback.

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

Sidebar

Related Questions

I encountered a very strange behavior when i m trying to insert a NSMutableDictonary
We have encountered a very strange class not found problem in our web app
Today I've encountered a very strange error while trying to get the contents of
i am relatively new to php and i've encountered a very strange problem. let
I have encountered a very weird situation in Python. I have a while True:
I'm trying to learn python and have encountered some strange behaviour. I am experimenting
I've encountered some very strange behaviour when debugging in VS 2010 with a WCF
I have just encountered very strange problem - my GWT app hosted on Google
I have encountered a very strange issue. Whenever I use the .NET membership provider
The story began with a very strange error while I was running my script

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.