Thursday 23 February 2017

Exceptions in Python


What is an Exception?
An Exception is an event or error that would happen during the execution of a program that would disturbs their execution. Whenever there is an error, Python generates an exception that could be handled. It basically prevents the program from getting crashed. When a Python script raises an exception, it must either handle the exception immediately otherwise it terminates and quits.
Why we use Exceptions
There was a valid as well as invalid exceptions occurred many times. Exceptions are convenient in many ways for handling errors and also the special conditions in a program. If we have some set of code which produces error, at that time we can use exception handling technique.

Handling an exception


If you have some suspicious code that may raise an exception, you can defend your program by placing the suspicious code in a try: block. After the try: block, include a except: statement, followed by a block of code that handles the problem as elegantly as possible.
If you have any queries? Mention it in the comment section, we will clarify you soon…!

No comments:

Post a Comment