Quantcast
Channel: CodeSection,代码区,Python开发技术文章_教程 - CodeSec
Viewing all articles
Browse latest Browse all 9596

Exceptions in Python

$
0
0

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.

Click here for obtain source…

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

Viewing all articles
Browse latest Browse all 9596

Trending Articles