Question:

What are Exception Handling? How do you achieve it in Python?

Answer:

Exception Handling prevents the codes and scripts from breaking on receipt of an error at run -time might be at the time doing I/O, due to syntax errors, data types doesn’t match. Generally it can be used for handling user inputs.
The keywords that are used to handle exceptions in Python are:
try – it will try to execute the code that belongs to it. May be it used anywhere that keyboard input is required.
except – catches all errors or can catch a specific error. It is used after the try block.x = 10 + ‘Python’ #TypeError: unsupported operand type(s) …. try:
x = 10 + ‘Python’
except:
print(“incompatible operand types to perform sum”)
raise – force an error to occur
o raise TypeError(“dissimilar data types”)
finally – it is an optional clause and in this block cleanup code is written here following “try” and “except”.


Keywords:

© 2017 QuizBucket.org