try-except-else question in Sage Cloud cell

62 views
Skip to first unread message

c. e. larson

unread,
Mar 5, 2015, 2:16:27 PM3/5/15
to sage-...@googlegroups.com
the "else" in the following code raises a "syntax" error when run in a Sage Cloud cell:

try:
    print "try now"
except:
    print "some exception"
else:
    print "made it to else"

*but* it runs normally if the code is in a function definition or even a junk for loop, like:

for i in [0]:
    try:
        print "try now"
    except:
        print "some exception"
    else:
        print "made it to else"

is this a bug, or is there some other reason to explain the difference in behavior?

thanks,

craig

Harald Schilly

unread,
Mar 5, 2015, 2:59:39 PM3/5/15
to sage-...@googlegroups.com, Sagemath Help
On Thu, Mar 5, 2015 at 8:16 PM, c. e. larson <mat...@gmail.com> wrote:
> is this a bug, or is there some other reason to explain the difference in
> behavior?

yes, it's a bug! cells are split up into smaller execution blocks, but
obviously shouldn't be split in that case.

very similar is the for-else construction, which should work, though.
I think I tested the try-else back then, too, but I don't remember :-(

-- harald

Hal Snyder

unread,
Jul 12, 2016, 2:17:40 PM7/12/16
to sage-cloud, he...@sagemath.com
This was smc issue #694, closed today. Tested with for-else, too.
Reply all
Reply to author
Forward
0 new messages