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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:47:41+00:00 2026-05-27T04:47:41+00:00

The following code raises a syntax error: >>> for i in range(10): … print

  • 0

The following code raises a syntax error:

>>> for i in range(10):
...     print i
...     try:
...        pass
...     finally:
...        continue
...     print i
...
  File "<stdin>", line 6
SyntaxError: 'continue' not supported inside 'finally' clause

Why isn’t a continue statement allowed inside a finally clause?

P.S. This other code on the other hand has no issues:

>>> for i in range(10):
...     print i
...     try:
...        pass
...     finally:
...        break
...
0

If it matters, I’m using Python 2.6.6.

  • 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-27T04:47:41+00:00Added an answer on May 27, 2026 at 4:47 am

    The use of continue in a finally-clause is forbidden because its interpretation would have been problematic. What would you do if the finally-clause were being executed because of an exception?

    for i in range(10):
        print i
        try:
           raise RuntimeError
        finally:
           continue        # if the loop continues, what would happen to the exception?
        print i
    

    It is possible for us to make a decision about what this code should do, perhaps swallowing the exception; but good language design suggests otherwise. If the code confuses readers or if there is a clearer way to express the intended logic (perhaps with try: ... except Exception: pass; continue), then there is some advantage to leaving this as a SyntaxError.

    Interestingly, you can put a return inside a finally-clause and it will swallow all exceptions including KeyboardInterrupt, SystemExit, and MemoryError. That probably isn’t a good idea either 😉

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

Sidebar

Related Questions

the following code raises the aforementioned error, how can I fix that? require 'mechanize'
The following code raises a runtime error: #include <iostream> #include <iterator> #include <ext/slist> class
Consider this code: datestring = date.min.strftime(%d-%m-%Y) date = datetime.strptime(datestring,%d-%m-%Y) This raises the following error:
The following code raises an ambiguous reference to value at compile time: import flash.display.Sprite;
I have the following code below: BEGIN TRY BEGIN TRANSACTION -- DO SOMETHIING COMMIT
The following code raises a KeyError exception: addr_list_formatted = [] addr_list_idx = 0 for
in the following code begin raise StandardError, 'message' #some code that raises a lot
I am getting the an error on the following code in one of my
Given the following situation: @try { @try { // raises an exception :) [receiver
I have the following code in .py file: import re regex = re.compile( rULLAT:\

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.