[Python-bugs-list] [ python-Bugs-467381 ] print statement and exception

noreply@sourceforge.net noreply@sourceforge.net
Tue, 02 Oct 2001 20:08:11 -0700


Bugs item #467381, was opened at 2001-10-02 19:19
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=467381&group_id=5470

Category: Python Interpreter Core
>Group: Not a Bug
>Status: Closed
>Resolution: Invalid
Priority: 5
Submitted By: paul rubin (phr)
>Assigned to: Guido van Rossum (gvanrossum)
Summary: print statement and exception

Initial Comment:
a = 3
b = 0
try:
  print "quotient is",a/b
except: pass
print "sum is", a+b

prints something like "quotient is sum is 3".
The first print statement prints "quotient is"
before the exception is thrown, and then doesn't
print the final newline.  The final newline should
be protected by the equivalent of a "finally" clause.




----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-10-02 20:08

Message:
Logged In: YES 
user_id=6380

Sorry, this is how it's defined. The print statement does
its things one at a time. If one of its things raises an
exception, then the remaining things won't be printed --
including the newline.

If that's not what you want, calculate the value and catch
the exception before printing the value, or use a print with
a trailing comma (suppresses the newline printing) and use
an empty print statement separately (supplies the newline),
like this:

try:
  print "quotient is", a/b,
except: pass
print


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=467381&group_id=5470