Exception Handling in Python
CBSE · Class 12 · Computer Science
NCERT Solutions for Exception Handling in Python — CBSE Class 12 Computer Science.
Interactive on Super Tutor
Studying Exception Handling in Python? Get the full interactive chapter.
Quizzes, flashcards, AI doubt-solver and a step-by-step study plan — built for ncert solutions and more.
1,000+ Class 12 students started this chapter today

This is just one of 11+ visuals inside Super Tutor's Exception Handling in Python chapter
Explore the full set5 worked solutions below. Unlock all 9 free in Super Tutor
EXERCISE
1“Every syntax error is an exception but every exception cannot be a syntax error.” Justify the statement.Show solution
But many exceptions occur after the program has started executing, even when the program is syntactically correct. Examples are ZeroDivisionError when dividing by zero, NameError when a variable is not defined, and IOError when a file cannot be opened. These are exceptions, but not syntax errors. So, every exception cannot be a syntax error.
Not sure why a step works? check your working in Super Tutor
2When are the following built-in exceptions raised? Give examples to support your answers.Show solution
- IOError: Raised when the file specified in a program statement cannot be opened. For example, trying to open a file that is not present.
- NameError: Raised when a local or global variable name is not defined. For example, using a variable before assigning a value to it.
- ZeroDivisionError: Raised when the denominator in a division operation is zero. For example, `10/0`.
Not sure why a step works? check your working in Super Tutor
3What 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).Show solution
Example code to accept two numbers and display the quotient, raising an exception if the denominator is zero:
```python
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
if num2 == 0:
raise ZeroDivisionError("Denominator cannot be zero")
else:
quotient = num1 / num2
print("Quotient =", quotient)
```
If the second number is `0`, the program raises `ZeroDivisionError` and does not continue with the division.
Not sure why a step works? check your working in Super Tutor
4Use assert statement in Question No. 3 to test the division expression in the program.Show solution
```python
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
assert(num2 != 0), "Denominator should not be zero"
quotient = num1 / num2
print("Quotient =", quotient)
```
Here, `assert(num2 != 0)` checks the division expression indirectly by ensuring the denominator is not zero. If `num2` is `0`, the message "Denominator should not be zero" is displayed and the program stops.
Not sure why a step works? check your working in Super Tutor
5Define the following:Show solution
b) Throwing an exception: Creating an exception object and handing it over to the runtime system when an error occurs; this causes control to jump to an exception handler.
c) Catching an exception: Executing a code block designed to handle a particular exception when that exception is raised. In Python, exceptions are caught in the try block and handled in the except block.
Not sure why a step works? check your working in Super Tutor
4 more solved questions in Exception Handling in Python
Every remaining exercise is solved step by step in Super Tutor, plus practice quizzes and flashcards for this chapter. Free to start.
Stuck on a step?
Ask Super Tutor AI to explain any solution on this page in a simpler way — free, 24x7.
Ask a Doubt FreeFrequently Asked Questions
What are the important topics in Exception Handling in Python for CBSE Class 12 Computer Science?
How to score full marks in Exception Handling in Python — CBSE Class 12 Computer Science?
Where can I get free NCERT Solutions for Exception Handling in Python Class 12 Computer Science?
Sources & Official References
- NCERT Official — ncert.nic.in
- CBSE Academic — cbseacademic.nic.in
- CBSE Official — cbse.gov.in
- National Education Policy 2020 — education.gov.in
Content is aligned to the official syllabus. Refer to the board website for the latest curriculum.
More resources for Exception Handling in Python
Practice Quiz
Test yourself with a quick quiz
Important Questions
Practice with board exam-style questions
Revision Notes
Key points for last-minute revision
Formula Sheet
All formulas in one place
Chapter Summary
Understand the chapter at a glance
Concept Maps
See how topics connect visually
Study Plan
Step-by-step plan to ace this chapter
Flashcards
Quick-fire cards for active recall
Syllabus
What topics to cover
For serious students
Get the full Exception Handling in Python chapter — for free.
Quizzes, flashcards, AI doubt-solver and a step-by-step study plan for CBSE Class 12 Computer Science.