Exceptions: Difference between revisions

m (Re-alphabetized.)
Line 244:
=={{header|Python}}==
 
'''Defining an exception type'''
===try-except-finally-else===
 
import exceptions
'''Interpreter''': Python 2.5
class SillyError(exceptions.Exception):
def __init__(self,args=None):
self.args=args
 
'''Throwing an exception'''
Before Python 2.5 it was not possible to use finally and except together. (It was necessary to nest a separate ''try''...''except'' block inside of your ''try''...''finally'' block).
 
def spam():
raise SillyError, 'egg'
 
'''Handling exceptions'''
(Python 2.5 Interpreter)
 
===try-except-finally-else===
 
try:
foo()
except TypeErrorSillyError, se:
print se.args
bar()
finally:
Line 259 ⟶ 271:
# no exception occurred
quux()
 
Before Python 2.5 it was not possible to use finally and except together. (It was necessary to nest a separate ''try''...''except'' block inside of your ''try''...''finally'' block).
 
=={{header|Raven}}==
Anonymous user