Basic Python | Exception Handling with try except Statements


Errors and Exceptions

Handling Python errors or exceptions gracefully is an important part of building robust programs and algorithms. Here we see that an uncaught exception was raised when a wrong argument was passed to the function. With try and except statement we can handle it a smooth fashion as shown.
Raise Exceptions:
There can be scenarios were we should raise exceptions to avoid the system failures. Python allows you do it with raise exception functionality. The way you raise your own exceptions is with the raise statement,
Below snippets shows, finally statement in try and except and custom exception class

No comments:

Post a Comment

Note: only a member of this blog may post a comment.