AssertionError not caught?

L

LX

This one has me mystified good!

This works (print statement is executed as the Exception is caught) as
advertised:
try:
raise AssertionError
except AssertionError:
print "caught AssertionError"


But this one does not:

def test():
raise AssertionError

try:
test()
except AssertionError:
print "caught AssertionError"

other errors (e.g. IOError) work fine! This is on OSX 10.5.6, with the
standard Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)].

Is this a bug? Any hints / help would be much appreciated! Thank you.
 
C

Chris Rebert

This one has me mystified good!

This works (print statement is executed as the Exception is caught) as
advertised:
try:
raise AssertionError
except AssertionError:
print "caught AssertionError"


But this one does not:

def test():
raise AssertionError

try:
test()
except AssertionError:
print "caught AssertionError"

other errors (e.g. IOError) work fine! This is on OSX 10.5.6, with the
standard Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)].

Is this a bug? Any hints / help would be much appreciated! Thank you.

My Mac begs to differ:

~ $ cat Desktop/tmp.py
def test():
raise AssertionError

try:
test()
except AssertionError:
print "caught AssertionError"
~ $ /System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5
Desktop/tmp.py
caught AssertionError
~ $ /System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5
Python 2.5.1 (r251:54863, Feb 4 2008, 21:48:13)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin

The problem must lie elsewhere.

Cheers,
Chris
 
A

Alexander Kain

Thank you for restoring sanity to my world!

Indeed, it seems to have to do with the way that the WingIDE debugger
works - it actually catches the error correctly , but it -->sets a
breakpoint at the original raise first<---. This only occurs for the
AssertionError. The debugger can then be continued.

Thank you again!

This one has me mystified good!

This works (print statement is executed as the Exception is caught)
as
advertised:
try:
raise AssertionError
except AssertionError:
print "caught AssertionError"


But this one does not:

def test():
raise AssertionError

try:
test()
except AssertionError:
print "caught AssertionError"

other errors (e.g. IOError) work fine! This is on OSX 10.5.6, with
the
standard Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)].

Is this a bug? Any hints / help would be much appreciated! Thank you.

My Mac begs to differ:

~ $ cat Desktop/tmp.py
def test():
raise AssertionError

try:
test()
except AssertionError:
print "caught AssertionError"
~ $ /System/Library/Frameworks/Python.framework/Versions/2.5/bin/
python2.5
Desktop/tmp.py
caught AssertionError
~ $ /System/Library/Frameworks/Python.framework/Versions/2.5/bin/
python2.5
Python 2.5.1 (r251:54863, Feb 4 2008, 21:48:13)
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin

The problem must lie elsewhere.

Cheers,
Chris
 
S

Steve Holden

LX said:
This one has me mystified good!

This works (print statement is executed as the Exception is caught) as
advertised:
try:
raise AssertionError
except AssertionError:
print "caught AssertionError"


But this one does not:

def test():
raise AssertionError

try:
test()
except AssertionError:
print "caught AssertionError"

other errors (e.g. IOError) work fine! This is on OSX 10.5.6, with the
standard Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)].

Is this a bug? Any hints / help would be much appreciated! Thank you.

This works for me under Cygwin:
.... raise AssertionError
........ test()
.... except AssertionError:
.... print "caught AssertionError"
....
caught AssertionError
I note from your indentation that it looks as though your code was
guarded by some other statement. Is it possible it wasn't executed at all?

regards
Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,076
Latest member
OrderKetoBeez

Latest Threads

Top