From charlesreid1

Revision as of 05:40, 30 May 2017 by Admin (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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 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