Anonymous user
Flow-control structures: Difference between revisions
→Case 7 - Creating your own custom exceptions, raise: shorten version
(→{{header|Python}}: introduced an explicit header structure) |
(→Case 7 - Creating your own custom exceptions, raise: shorten version) |
||
Line 430:
# Let's call our custom error "StupidError"; it inherits from the Exception class
class StupidError(Exception): pass
# 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
# Output :
# Something stupid occurred: Segfault
</pre>
====Case 8 - continue====
<pre>
|