Exception Handling in Python

Class 12 · Computer Science · 8 Questions

5beginner🧠 Remember3 marksVery Short

Define the following:

9intermediate🔧 Apply3 marksShort Answer

What is the use of finally clause? Use finally clause in the problem given in Question No. 7.

3intermediate🔧 Apply3 marksLong Answer

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).

7intermediate🔧 Apply3 marksFill in the Blanks

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")

1intermediate💡 Understand2 marksShort Answer

“Every syntax error is an exception but every exception cannot be a syntax error.” Justify the statement.

2intermediate💡 Understand4 marksShort Answer

When are the following built-in exceptions raised? Give examples to support your answers.

4intermediate🔧 Apply2 marksShort Answer

Use assert statement in Question No. 3 to test the division expression in the program.

6intermediate💡 Understand2 marksShort Answer

Explain catching exceptions using try and except block.

Class 12 Computer Science Chapter 1: Exception Handling in Python — NCERT Questions & Answers