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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:19:26+00:00 2026-06-03T17:19:26+00:00

I have an application, that needs to be working in all modern Python versions,

  • 0

I have an application, that needs to be working in all “modern” Python versions, which means 2.5–3.2. I don’t want two code bases, so 2to3 is not an option.

Consider something like this:

def func(input):
    if input != 'xyz':
        raise MyException(some_function(input))
    return some_other_function(input)

How can I catch this exception, to get access to the exception object?
except MyException, e: is not valid in Python 3, and except MyException as e: is not valid in python 2.5.

Clearly it could have been possible to return the exception object, but I hope, i don’t have to do this.

  • 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-03T17:19:27+00:00Added an answer on June 3, 2026 at 5:19 pm

    This concern is addressed in the Py3k docs. The solution is to check sys.exc_info():

    from __future__ import print_function
    
    try:
        raise Exception()
    except Exception:
        import sys
        print(sys.exc_info()) # => (<type 'exceptions.Exception'>, Exception(), <traceback object at 0x101c39830>) 
        exc = sys.exc_info()[1]
        print(type(exc)) # => <type 'exceptions.Exception'>
        print([a for a in dir(exc) if not a.startswith('__')]) # => ['args', 'message']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that i am working on which needs actually a file
I am working on an application where we have 100 of jobs that's needs
If you have a Windows application that needs to write working files as part
I have a threaded console application that is working fine, but it's architecture needs
I have an application that needs to work with a vendor-supplied API to do
I have an application that needs to check a website feed every second. Sometimes
I have an application that needs to highlight individual pixels on an image. I
I have an application that needs to determine whether a user has made a
I have an application that needs branding when downloaded in certain continents. When installed
I have an application that needs to operate on Windows 2000. I'd also like

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.