Anonymous user
Exceptions: Difference between revisions
→try-except-finally-else: clarify
m (Re-alphabetized.) |
(→try-except-finally-else: clarify) |
||
Line 244:
=={{header|Python}}==
'''Defining an exception type'''
===try-except-finally-else===▼
import exceptions
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:
foo()
except
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}}==
|