Computer Science
Define the following:
- Exception Handling
- Throwing an exception
- Catching an exception
Python Exception Handling
12 Likes
Answer
- Exception Handling — The process of writing additional code in a program to give proper messages or instructions to the user upon encountering an exception is known as exception handling.
- Throwing an exception — Throwing an exception refers to the process of creating an exception object and passing it to the runtime system or the appropriate exception handler.
- Catching an exception — Catching an exception refers to the process of executing a suitable handler or block of code specifically designed to handle that particular exception when it occurs during program execution.
Answered By
3 Likes
Related Questions
What is the use of a raise statement? Write a code to accept two numbers and display the quotient. Appropriate exception should be raised if the user enters the second number (denominator) as zero (0).
Use assert statement in Question No. 3 to test the division expression in the program.
Explain catching exceptions using try and except block.
Consider the code given below and fill in the blanks.
print("Learning Exceptions...") try: num1 = int(input("Enter the first number")) num2 = int(input("Enter the second number")) quotient = (num1/num2) print("Both the numbers entered were correct") except ...............: # to enter only integers print("Please enter only numbers") except ...............: # Denominator should not be zero print("Number 2 should not be zero") else: print("Great .. you are a good programmer") ...............: # to be executed at the end print("JOB OVER... GO GET SOME REST")