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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:13:32+00:00 2026-06-12T11:13:32+00:00

When I am executing a simple query (I am using tornado.database module) I handle

  • 0

When I am executing a simple query (I am using tornado.database module) I handle exceptions like this:

try:
    self.application.db.execute('DELETE FROM table_one WHERE a = 1')
except Exception, e:
    logging.warning('DB exception: %s' % e)
    self.set_status(500)
    return

If I want to do a transaction though, it would be smart to rollback it in case of exception:

try:
    self.application.db.execute('START TRANSACTION')
    self.application.db.execute('DELETE FROM table_one WHERE a = 1')
    self.application.db.execute('DELETE FROM table_two WHERE b = 2')
    self.application.db.execute('COMMIT')
except Exception, e:
    logging.warning('DB exception: %s' % e)
    self.set_status(500)
    self.application.db.execute('ROLLBACK')
    return

But what if rollback will cause an exception too (e.g. if connection fails)? Do I need to put a nested try-except block inside of the except block?

  • 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-12T11:13:34+00:00Added an answer on June 12, 2026 at 11:13 am

    Placing a nested try … except block in except block is a solution.
    But I would go for using finally:

    try:
      ...
    except ... :
    
    finally:
       # cleanup (close the connection, etc...)
    

    I mean if the rollback failed, there is pretty much nothing else to do then log the exception and cleanup, right?

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

Sidebar

Related Questions

I have the following query that I'm executing using a Python script (by using
Whats this?? my query is: Doctrine_Query::create() ->select('rec.*') ->from('Records rec') ->execute(); Records table contains more
I was doing a simple query using explain to know precisely the execution time.
Is it possible to connect to Sql Server for the purpose of executing simple
My question is rather simple. Let's suppose I'm executing the algorithm A star (search
I wanted to implement a simple python program using parallel execution. It's I/O bound,
After using the ebay API recently, I was expecting it to be as simple
I want to execute a mapreduce query, in erlang, that contains two map phases
I am doing a very simple select from a table like SELECT column FROM
I am executing the below query to get daily user signin details from my

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.