From charlesreid1

(Created page with "Class exceptions: ==Abstract datatype example== The case of exception handling for an abstract data type like a stack is pretty clear-cut: there are two explicit error case...")
 
No edit summary
Line 1: Line 1:
Class exceptions:  
Class exceptions:  


==Abstract datatype example==
==Abstract datatype example - exceptions following specifications==


The case of exception handling for an abstract data type like a stack is pretty clear-cut: there are two explicit error cases that it should handle, both when items are requested and the stack is empty. To raise these exceptions, we just do a variation of <code>raise Exception("oops")</code>:
The case of exception handling for an abstract data type like a stack is pretty clear-cut: there are two explicit error cases that it should handle, both when items are requested and the stack is empty. To raise these exceptions, we just do a variation of <code>raise Exception("oops")</code>:
Line 13: Line 13:


See [[StacksQueues/Python/ArrayStack#Class_implementation]]
See [[StacksQueues/Python/ArrayStack#Class_implementation]]
[[Category:CS]]
[[Category:Python]]
[[Category:Exceptions]]

Revision as of 05:41, 30 May 2017

Class exceptions:

Abstract datatype example - exceptions following specifications

The case of exception handling for an abstract data type like a stack is pretty clear-cut: there are two explicit error cases that it should handle, both when items are requested and the stack is empty. To raise these exceptions, we just do a variation of raise Exception("oops"):

class Empty(Exception):
    pass

Done. Now we can do raise Empty("oops, empty stack").

See StacksQueues/Python/ArrayStack#Class_implementation