Answer Posted / chaitanya
Errors detected during execution of program are called exceptions. Exceptions can be handled using the try..except statement. We basically put our usual statements within the try-block and put all our error handlers in the except-block.
try…except demo code:
>>> while True:
try:
x = int(raw_input("Enter no. of your choice: "))
break
except ValueError:
print "Oops! Not a valid number. Attempt again"
Enter no. of your choice: 12ww
Oops! Not a valid number. Attempt again
Enter no. of your choice: hi there
Oops! Not a valid number. Attempt again
Enter no. of your choice: 22
>>>
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
What opens a py file?
Is Python good for backend?
Why do we use raw_input in python?
List out atleast two loop control statements?
How to append to a string in Python?
What are middlewares in python?
How to give comments in python?
Is r similar to python?
How can you create empty numpy array in python?
How is a .pyc file different from a .py file?
What does the
Is python duck typed?
What are the different environment variables identified by python?
What is iterable python?
What do you understand by the process of compilation and linking in python?