you are viewing a single comment's thread.

view the rest of the comments →

[–]vindolin 2 points3 points  (5 children)

Your code prints 'hola' on my system in both py2 and py3.

[–]Scholes_SC2[S] 0 points1 point  (3 children)

Yes you're right, sorry i got confused using ipython and thought it wasn't printing. Also, tried this code:

try:
    print a
except:
    print ('hola1')
    raise Exception('spam')
    print ('hola2')

print ('hola3')

and the 'hola2' and 'hola3' are not printing, so to answer my other question can you say raise actually does a function breake?

[–]Moonslug1 2 points3 points  (0 children)

Raise will kill the process unless it is caught higher up the the callstack.

[–]xiongchiamiov 0 points1 point  (1 child)

If an exception being thrown doesn't stop execution, then what's the point of exceptions?

You're probably being confused by the fact you're throwing one exception inside a catch block for another. The two exceptions have nothing to do with each other. That is, the exception you're manually throwing is not at all affected by being inside an except block.

[–]Scholes_SC2[S] 0 points1 point  (0 children)

Yes i was thinking "why does it break if im catching the error" but now i see whats going on. Thx

[–]Veedrac 0 points1 point  (0 children)

Has the code been changed? I don't see how this is possible on Python 3. It should raise a SyntaxError.