Exceptions: Difference between revisions
Content deleted Content added
→Throw exceptions: std::bad_exception example function |
|||
Line 574: | Line 574: | ||
def __init__(self,args=None): |
def __init__(self,args=None): |
||
self.args=args</python> |
self.args=args</python> |
||
Note: In most cases new exceptions are defined simply using the ''pass'' statement. For example: |
|||
<python> |
|||
class MyInvalidArgument(ValueError): |
|||
pass |
|||
</python> |
|||
This example makes "MyInvalidArgument" an type of ValueError (one of the built-in exceptions). It's simply declared as a subclass of the existing exception and no over-riding is necessary. (An except clause for ValueError would catch MyInvalidArgument exceptions ... but one's code could insert a more specific exception handler for the more specific type of exception). |
|||
===Throwing an exception=== |
===Throwing an exception=== |