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

  • Home
  • SEARCH
  • 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 494901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:32:32+00:00 2026-05-13T05:32:32+00:00

Note: i edited my Q (in the title) so that it better reflects what

  • 0

Note: i edited my Q (in the title) so that it better reflects what i actually want to know. In the original title and in the text of my Q, i referred to the source of the thrown exception; what i meant, and what i should have referred to, as pointed out in one of the high-strung but otherwise helpful response below, is the module that the exception class is defined in. This is evidenced by the fact that, again, as pointed out in one of the answers below the answer to the original Q is that the exceptions were thrown from calls to cursor.execute and cursor.next, respectively–which of course, isn’t the information you need to write the try/except block.

For instance (the Q has nothing specifically to do with SQLite or the PySQLite module):

from pysqlite2 import dbapi2 as SQ

try:
    cursor.execute('CREATE TABLE pname (id INTEGER PRIMARY KEY, name VARCHARS(50)')
except SQ.OperationalError:
    print("{0}, {1}".format("table already exists", "... 'CREATE' ignored")) 

#

cursor.execute('SELECT * FROM pname')
while 1:
    try:
        print(cursor.next())
    except StopIteration:
        break

#

i let both snippets error out to see the exception thrown, then coded the try/finally blocks–but that didn’t tell me anything about which module the exception class is defined. In my example, there’s only a single imported module, but where there are many more, i am interested to know how an experienced pythonista identifies the exception source (search-the-docs-till-i-happen-to-find-it is my current method).

[And yes i am aware there’s a nearly identical question on SO–but for C# rather than python, plus if you read the author’s edited version, you’ll see he’s got a different problem in mind.]

  • 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-13T05:32:32+00:00Added an answer on May 13, 2026 at 5:32 am

    the second [[exception was thrown]] from a python core module

    False: it was thrown from a call to cursor.next, exactly like the first one was thrown from a call to cursor.execute — it’s hard to say why you’re baldly asserting this counterfactual, but contrary to fact it nevertheless remains.

    If you’re speaking about, what module an exception class was defined in, as opposed to, as you say, where it was thrown from, that’s a completely different thing of course:

    try:
      ...whatever...
    except Exception, e:
      print "caught an exception defined in module", e.__class__.__module__
    

    Built-in exceptions are actually defined in module exceptions, as this code will also tell you. Of course, once you have the module name (which this snippet gives you), you can further explore, if you wish, e.g. by obtaining the module object (just index sys.modules by module name), etc.

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

Sidebar

Related Questions

[Note: Title and text were heavily edited to make it more clear that I'm
NOTE: EDITED The real-world situation is a series of events that each have two
[Editor's note: I have edited the title to try to make this useful to
Please note, sarnold has heavily edited the question; the original question, in its entirety,
NOTE: Edited to add the Model The Problem: a querystring guid value is giving
Note: Although my particular context is Objective-C, my question actually transcends programming language choice.
NOTE: I am aware of the SVN relocate switch, I just need to know
(Note: This post has been edited to show specific use case. See bottom.) I
I would like to have questions marked as Edited, but I dont know what
Note: Edited the sample to reflect my actual problem, which was a trailing comma

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.