Exceptions in Python

kavi nila
kavi nila
Feb 23, 2017 · 1 min read

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.

Click here to obtain source…

If you have any queries? Mention it in the comment section, we will clarify you soon…!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade