Flow-control structures: Difference between revisions

(→‎{{header|Python}}: introduced an explicit header structure)
Line 430:
# Let's call our custom error "StupidError"; it inherits from the Exception class
class StupidError(Exception): pass
def __init__(self, value): # 'value' is a constructor argument
self.value = value
def __str__(self):
return repr(self.value)
# Try it out.
Line 440 ⟶ 436:
raise StupidError("Segfault") # here, we manually 'raise' the error within the try block
except StupidError, details: # 'details' is the StupidError object we create in the try block.
print 'Something stupid occurred:', details.value # so we access the value we had stored for it...
# Output :
# Something stupid occurred: Segfault
</pre>
 
====Case 8 - continue====
<pre>
Anonymous user