---
title: "Exception Handling Class 12 Computer Science: Notes, Q&A"
description: "Exception handling class 12 computer science (083): notes on try, except, finally, a table of built-in exceptions, 6 tested programs and 19 questions."
canonical: https://learn.modernagecoders.com/cbse-class-12-computer-science-exception-handling
source: src/pages/cbse-class-12-computer-science-exception-handling.html
---
> Exception handling class 12 computer science (083): notes on try, except, finally, a table of built-in exceptions, 6 tested programs and 19 questions.

Start here

## Courses that take this chapter further

Handlers make sense only inside real programs, so each of these puts them to work: in board answers, in Python projects, or in a program that talks to a database.

[![Computer Science Class 11 and 12 course thumbnail](/images/ip-cs-class-11-12.webp)  Board / 083 track Computer Science 11 and 12 Exception handling sits between functions and files here, so your file programs can use handlers from the first one. Open the course →](/courses/cbse-icse-computer-science-class-11-12-python-java-complete-course)[![Python for Teens course thumbnail](/images/python-teens.webp)  Python / Projects Python for Teens Build small programs that survive wrong input. A useful route if error messages still feel like a telling-off instead of a clue. Open the course →](/courses/python-complete-masterclass-teens)[![MySQL for Teens course thumbnail](/images/mysql-teens.webp)  SQL / Apps MySQL for Teens The closing month joins Python to a database, which is a natural place to use what you learn in this chapter. Open the course →](/courses/mysql-mastery-for-teens)

Ans. The short version

Exception handling in class 12 computer science (CBSE 083, 2026-27) means dealing with errors that appear while a program is running, using try, except and finally. Risky statements go in try; the except block that names the raised exception runs; finally runs either way. If no except matches, finally still runs and the program then stops with the error. Modern Age Coders teaches it live, personalised one to one, at your own days and timing, inside the file programs where it is examined. A priority demo gives you one full class to judge first.

Q1. What is an exception?

## Exception handling in Python Class 12 notes: errors and exceptions

An exception is an error that Python meets while a program is running, such as dividing by zero or opening a file that is not there. Handling it means writing code that deals with the problem so the program need not stop.

| Kind of mistake | When it shows | Example | Can try-except help? |
| --- | --- | --- | --- |
| Syntax error | Before any line runs | A missing colon after `if` | No. The program never starts, so its try never runs |
| Exception (run-time error) | While running, at one statement | `int("twelve")` | Yes, if that statement is inside a try |
| Logical error | Never reported. The answer is wrong | `total = marks * 3` where + was meant | No. Python sees nothing wrong |

### Nine built-in exceptions, and what sets each one off

Learn the left column by running the middle one. The last column is the message Python 3.14 printed for us; your lab version may word it a little differently, and the exam wants the name.

| Exception | A statement that raises it | Message |
| --- | --- | --- |
| **ZeroDivisionError** | `60 / 0` | division by zero |
| **ValueError** | `int("twelve")` | invalid literal for int() with base 10: 'twelve' |
| **TypeError** | `"Rs " + 50` | can only concatenate str (not "int") to str |
| **NameError** | `print(totl)` | name 'totl' is not defined |
| **IndexError** | `[4, 7][2]` | list index out of range |
| **KeyError** | `{"tea": 10}["milk"]` | 'milk' |
| **FileNotFoundError** | `open("gone.txt")` | [Errno 2] No such file or directory: 'gone.txt' |
| **EOFError** | `pickle.load(f)` with no record left | Ran out of input |
| **ModuleNotFoundError** | `import maths` | No module named 'maths' |

**ValueError or TypeError?** Ask whether the type was acceptable. `int("twelve")` was given a string, which `int()` accepts, but this string's value will not convert: ValueError. `len(5)` was given a number, which `len()` never accepts: TypeError.

Q2. Which block runs?

## How does try, except, finally work in Class 12?

Python runs try until a statement fails, jumps at once to the first except that names that exception, and runs finally on the way out in every case. The rest of the try block is skipped and is not resumed.

***Five letters, three paths**tanks.py*

```
def fill(litres, tanks):
    try:
        print("A", end=" ")
        each = litres // int(tanks)
        print("B", end=" ")
    except ZeroDivisionError:
        print("C", end=" ")
    finally:
        print("D", end=" ")
    print("E")

fill(90, "3")
fill(90, "0")
fill(90, "x")
```

**Output**

```
A B D E
A C D E
A D
ValueError: invalid literal for int() with base 10: 'x'
```

Only the last line of the error report is shown. The third call has no matching except, so E never prints.

### Read it as five steps

1. #### Enter try

  Statements run in order, as usual.
2. #### Something fails

  The remaining try statements are dropped. That is why B is missing in the second call.
3. #### Look for a match

  The except clauses are checked from the top, and at most one of them runs.
4. #### Run finally

  With a failure or without, matched or not.
5. #### Go on, or stop

  If the exception was handled, or never happened, the lines below continue. If not, the program ends with the error.

### Five situations in one table

| Situation | try | except | finally | Statements below |
| --- | --- | --- | --- | --- |
| No exception | Runs fully | Skipped | Runs | Run |
| Exception with a matching except | Runs up to the failure | Runs | Runs | Run |
| Exception with no matching except | Runs up to the failure | Skipped | Runs | Not run, program stops |
| The except block itself fails | Runs up to the failure | Runs up to its own failure | Runs | Not run, program stops |
| `return` inside try | Runs up to the return | Skipped | Runs, then the value goes back | Not run, function has ended |

***return meets finally**check.py*

```
def check(n):
    try:
        return 100 // n
    except ZeroDivisionError:
        return -1
    finally:
        print("checked", n)

print(check(8))
print(check(0))
```

**Output**

```
checked 8
12
checked 0
-1
```

### Rules for writing the blocks

- A `try` needs at least one `except` or a `finally`. Alone, it is a syntax error.
- `try` with only `finally` is allowed: the clean-up happens, then the error still stops the program.
- There may be many `except` clauses but only one `finally`, and it comes last.
- Put the particular exception above a general one such as `Exception`, or it is never reached.
- An `except:` with no name catches everything, spelling mistakes in your own code included. Name the exception instead.

A value is also being returned here. If that part is shaky, start with [functions for Class 12](/cbse-class-12-computer-science-functions).

Q3. Where do you use it?

## Exception handling programs for Class 12

You need a handler wherever the program depends on something it does not control: what a person types, whether a file exists, how many records a file holds, or whether a key is present.

***1. Ask again until it is right**typed values included*

```
def read_marks(limit=70):
    """Return a whole number from 0 to limit."""
    while True:
        try:
            marks = int(input("Theory marks: "))
            if 0 <= marks <= limit:
                return marks
            print("Must be 0 to", limit)
        except ValueError:
            print("Digits only, please")

print("Saved:", read_marks())
```

**Output**

```
Theory marks: sixty
Digits only, please
Theory marks: 88
Must be 0 to 70
Theory marks: 61
Saved: 61
```

88 is not an exception. It converts well; a plain `if` rejects it.

***2. Two things can go wrong**two excepts*

```
menu = {"idli": 30, "vada": 25, "dosa": 60}

def order_cost(item, plates):
    """Return the cost, or a message."""
    try:
        return menu[item] * int(plates)
    except KeyError:
        return "Not on the menu: " + item
    except ValueError:
        return "Plates must be a number"

print(order_cost("idli", "4"))
print(order_cost("puri", "2"))
print(order_cost("dosa", "two"))
print(order_cost("puri", "two"))
```

**Output**

```
120
Not on the menu: puri
Plates must be a number
Not on the menu: puri
```

The last call has both faults. `menu[item]` is worked out first, so KeyError is the one raised.

***3. A text file that may be missing**poem.txt has 3 lines*

```
def count_lines(filename):
    """Display the number of lines in a text file."""
    try:
        with open(filename) as f:
            lines = f.readlines()
        print(filename, "has", len(lines), "lines")
    except FileNotFoundError:
        print(filename, "was not found")
    finally:
        print("Search finished")

count_lines("poem.txt")
count_lines("peom.txt")
```

**Output**

```
poem.txt has 3 lines
Search finished
peom.txt was not found
Search finished
```

***4. The end of a binary file**EOFError as a signal*

```
import pickle

with open("nursery.dat", "wb") as f:
    for plant in (["Tulsi", 12], ["Neem", 4], ["Rose", 9]):
        pickle.dump(plant, f)

def total_plants():
    """Return the number of plants in all records."""
    total = 0
    f = open("nursery.dat", "rb")
    try:
        while True:
            total += pickle.load(f)[1]
    except EOFError:
        print("No more records")
    finally:
        f.close()
    return total

print("Plants:", total_plants())
```

**Output**

```
No more records
Plants: 25
```

The marking scheme for the 2026-27 sample paper gives a mark in Question 36 for exactly this: `load()` in a while loop with try and except.

***5. Skip bad data, keep the rest**try inside a loop*

```
def average(readings):
    """Return the mean of the valid readings."""
    total = good = 0
    for r in readings:
        try:
            total += float(r)
            good += 1
        except ValueError:
            print("Skipped", r)
    try:
        return total / good
    except ZeroDivisionError:
        return "No valid reading"

print(average(["36.5", "NA", "38.5"]))
print(average(["NA", "-"]))
```

**Output**

```
Skipped NA
37.5
Skipped NA
Skipped -
No valid reading
```

With the try outside the loop, the first NA would have ended the whole loop.

***6. The order of the excepts**a common trap*

```
try:
    seats = int("5a")
except Exception:
    print("Something failed")
except ValueError:
    print("Not a whole number")
finally:
    print("Counter closed")
```

**Output**

```
Something failed
Counter closed
```

ValueError is a kind of Exception, so the general clause takes it first. Swap the two clauses to get the useful message.

Next, use these inside longer answers: [file handling for Class 12](/cbse-class-12-computer-science-file-handling), then [CSV and binary files](/cbse-class-12-computer-science-csv-and-binary-files).

Q4. How much is enough?

## What is in the exception handling syllabus for Class 12 in 2026-27?

The 083 syllabus line is brief: introduction, and handling exceptions using try-except-finally blocks. CBSE gives the chapter no marks of its own; it shares the 40 marks of Unit 1.

### Read about, but not named in the line

| Idea | In one sentence |
| --- | --- |
| `raise` | Makes an exception happen on purpose. |
| `assert` | Checks a condition and raises AssertionError if it is false. |
| `else` after except | Runs only when try finished with no exception. |
| `except ValueError as e` | Keeps the exception in a name so its message can be printed. |

Textbooks often cover these, and your school may ask about them in a class test. Know the sentence for each. For the board, master the three named blocks first.

In the official 2026-27 sample paper, a 1-mark question asks what an except block leaves in a text file, and the 5-mark binary file answer relies on EOFError. So the chapter is examined through other chapters too. All the topics are listed on [the Class 12 CS syllabus page](/cbse-class-12-computer-science-syllabus-2026-27).

### Mistakes a marker sees first

| What is written | What goes wrong | Write instead |
| --- | --- | --- |
| `n = int(input())` above the try | The ValueError happens outside, uncaught | Put the conversion inside try |
| `except FileNotFound:` | NameError, when an exception arrives there | The full name, FileNotFoundError |
| `f.close()` as the last line of try | Skipped when an earlier line fails | `with`, or close in finally |
| Closing `f` in finally when `open()` was in the try | If open failed, `f` does not exist | Open before the try, or use `with` |
| Twenty lines inside one try | Nobody can tell which line was expected to fail | Only the risky statements |

Q5. Can you name it and trace it?

## Exception handling Class 12 important questions with answers

Nineteen original questions: naming the exception, tracing the blocks, correcting code and writing short functions. Decide the exception first in each one, then follow the blocks.

### One mark each

1. Which block runs whether or not an exception occurs? Answer`finally`.
2. Name the exception: `int("7.5")`Answer**ValueError.**`int()` converts strings of whole numbers only. `float("7.5")` would work.
3. Name the exception: `marks = (40, 35)` followed by `marks[0] = 45`Answer**TypeError.** A tuple does not allow item assignment.
4. Name the exception: `"Pune".index("z")`Answer**ValueError**, since the letter is not there. `find()` would give -1 without any exception.
5. Can a try block be followed by a finally block alone? Answer Yes. The exception is not handled, but the finally statements run before the program stops.
6. True or False: a missing bracket in a program can be handled by a try block in that same program. Answer**False.** It is a syntax error, found before the program starts running.
7. If no exception occurs in try, which block is skipped? Answer The `except` block.
8. Fill in the blank to complete the pair: `try:` with `price = rates["bus"]`, then `______ KeyError:`Answer`except`
9. **Assertion (A):** A program with an `except ValueError` clause may still stop with an error. **Reason (R):** An except clause deals only with the kind of exception it names. Answer**Both A and R are true, and R is the correct explanation of A.**
10. **Assertion (A):** finally cannot be written without except. **Reason (R):** finally is used for statements that must run in every case. Answer**A is false but R is true.**

### Two marks, theory

1. Differentiate between a syntax error and an exception, with one example of each. Answer A syntax error breaks the rules of the language and is found before the program runs, such as `print("Hi"`. An exception arises while a correctly written program is running, such as `10 / 0`, which raises ZeroDivisionError.
2. What is the use of the finally block? Give one situation from your practical file. Answer It holds statements that must run in every case, usually clean-up. Example: closing a binary file after reading it, whether the reading ended normally or with an exception.

### Two marks, correct the code

1. Remove the four errors and underline each correction.

  ***Q13**four errors*

  ```
  Try:
      rate = 500 / int("5")
      print(rate)
  exept ZeroDivisionError
      print("Cannot divide")
  Finally:
      print("Over")
  ```

  Answer

  ***Q13 corrected**half a mark each*

  ```
  try:                            # 1. small t
      rate = 500 / int("5")
      print(rate)
  except ZeroDivisionError:       # 2. spelling  3. colon
      print("Cannot divide")
  finally:                        # 4. small f
      print("Over")
  ```

  **Output**

  ```
  100.0
  Over
  ```

### Three marks, write the function

1. Write `letter_at(word, pos)`, where `pos` arrives as a string. Return the letter at that index. Return "Not a number" or "Out of range" when the position is unusable. Answer

  ***Q14**one good answer*

  ```
  def letter_at(word, pos):
      try:
          return word[int(pos)]
      except ValueError:
          return "Not a number"
      except IndexError:
          return "Out of range"

  print(letter_at("Kaveri", "2"))
  print(letter_at("Kaveri", "two"))
  print(letter_at("Kaveri", "6"))
  ```

  **Output**

  ```
  v
  Not a number
  Out of range
  ```
2. Each line of a text file should hold a whole number. Write `add_up(filename)` to return the sum, ignoring lines that do not convert, and to return "No file" if the file is missing. Answer

  ***Q15**donations.txt holds 250, five, 400*

  ```
  def add_up(filename):
      total = 0
      try:
          with open(filename) as f:
              for line in f:
                  try:
                      total += int(line)
                  except ValueError:
                      pass
      except FileNotFoundError:
          return "No file"
      return total

  print(add_up("donations.txt"))
  print(add_up("donation.txt"))
  ```

  **Output**

  ```
  650
  No file
  ```

  `int()` ignores the newline at the end of each line, so no `strip()` is needed.

### Two marks, output

1. Predict the output.

  ***Q16**predict*

  ```
  def ask(values, i):
      try:
          print(values[i] + 1)
      except IndexError:
          print("too short")
      except TypeError:
          print("not a number")
      finally:
          print("*")

  ask([4, "7"], 0)
  ask([4, "7"], 1)
  ask([4, "7"], 2)
  ```

  Answer**Output**`5``*``not a number``*``too short``*`Index 1 exists but holds a string, so adding 1 is a TypeError. Index 2 does not exist.
2. Predict the output.

  ***Q17**predict*

  ```
  total = 0
  for x in ["4", "0", "b", "2"]:
      try:
          total += 8 // int(x)
      except ZeroDivisionError:
          total += 100
      except ValueError:
          total += 1000
  print(total)
  ```

  Answer**Output**`1106`2, then 100 for the zero, then 1000 for the letter, then 4. The loop carries on because the try is inside it.
3. Predict the output.

  ***Q18**predict*

  ```
  def size(n):
      try:
          if n > 2:
              return "big"
          print("small")
      finally:
          print("end")

  print(size(5))
  size(1)
  ```

  Answer**Output**`end``big``small``end`In the first call the value waits while finally prints, so "end" comes before "big".
4. The file fan.txt does not exist before this code is run. What does it show?

  ***Q19**predict*

  ```
  def log(temp):
      f = open("fan.txt", "a")
      try:
          f.write(str(int(temp) + 1) + ";")
      except ValueError:
          f.write("?;")
      finally:
          f.close()

  for t in ["24", "hot", "30"]:
      log(t)
  f = open("fan.txt")
  print(f.read())
  f.close()
  ```

  Answer**Output**`25;?;31;`For "hot", `int()` fails before anything is written, so only the handler writes.

Enjoyed the tracing? There is a whole page of it: [Class 12 CS output questions](/cbse-class-12-computer-science-output-questions).

### Your own red text

One to one classes begin with the error messages from your lab work. You read the last line first, name the exception, and find the statement.

### Break it on purpose

You make a working file program fail in three ways, then add a handler for each and prove that it runs.

### Letters in the margin

Trace questions are done as A, B, C, D, E, as in the tank program, until the path through the blocks is automatic.

One to one only

## Short chapter, so learn it on your own programs

Exceptions are personal: yours come from the way you type, name files and convert values. That is why these classes are personalised one to one and nothing else, on your days, at your timing, with your code on the screen. A priority demo is the way to try it, a full class whose fee comes off the first month when you enrol. The free demo class is the lighter choice. Fees are monthly, nothing is charged for admission, and you are free to stop when a month ends.

Before you enrol · Try a class

### Priority demo, at a slot you pick

a full live class of about 45 to 60 minutes

- You run a file program of yours and the teacher breaks it
- You name each exception before Python tells you
- You add the handlers, and see which blocks run
- A written skill report covering exceptions, files and tracing

[Book a priority demo](/book-demo)

The classes · Choose your own timing

### Personalised one to one

₹4,999

per month, 4 private classes, fully flexible timing

- Exceptions taught together with text, binary and CSV files
- Debugging your practical file programs, which you write yourself
- Trace and correction questions until the path is automatic
- The rest of the 083 theory planned around your school tests

Ask for a personalised plan

If exceptions are your only worry, say so: the first classes can deal with just that and move on to files, where the marks are. If the trouble is deeper, in loops or in converting input, the teacher finds it early and goes back as far as needed. What you pay each month is shown on this page for your own country.

Studying outside India?

## For 083 students whose school is abroad

Whether your CBSE school is in Sharjah, Jeddah, Bahrain or Jakarta, the line "try-except-finally" in your syllabus is the same. We fix class hours around your school day and weekend.

| Where you live | Time difference | Usual class window, local time | Format |
| --- | --- | --- | --- |
| India every Indian city | Indian time | Any time you choose | Personalised 1-on-1 |
| UAE and Oman Dubai, Abu Dhabi, Sharjah, Muscat | 1 h 30 min behind India | 3:00 PM to 9:00 PM | Personalised 1-on-1 |
| Saudi Arabia, Qatar, Kuwait, Bahrain Riyadh, Jeddah, Dammam, Doha, Kuwait City, Manama | 2 h 30 min behind India | 3:00 PM to 9:00 PM | Personalised 1-on-1 |
| Nepal Kathmandu | 15 min ahead of India | 4:30 PM to 9:00 PM | Personalised 1-on-1 |
| Ethiopia and East Africa Addis Ababa and East Africa Time | 2 h 30 min behind India | 4:30 PM to 9:00 PM | Personalised 1-on-1 |
| Singapore and Malaysia Singapore, Kuala Lumpur | 2 h 30 min ahead of India | 3:30 PM to 9:00 PM | Personalised 1-on-1 |

An error message reads the same in every country, which makes this an easy chapter to teach on a shared screen. Keep Python open, keep your practical programs in one folder, and tell us the hours that are free at home.

What families say

## Rated 4.9 across 547 Google reviews

Real reviews from real families. We neither write nor commission them.

★★★★★

"The one step solution for my son. Modern Age Coders make learning coding so simple that kids love it. The teachers explain complex concepts clearly with practical exercises and interactive content."

Ria Mukherjee

Parent

★★★★★

"Modern Age Coders has been a game-changer for me. I struggled to grasp IT concepts and coding before joining, but their classes transformed everything. I can now confidently write complex programs with ease."

Samriddha Mondal

Student

★★★★★

"One of the most wonderful education centres out there. Education is not limited to school syllabus but focuses on skill development."

Vansh Agarwal

Student

★★★★★

"My child Dhairya is really enjoying the Modern Age Coders classes. This is his first online class and he eagerly looks forward to it. I can already see his improvement, and the teachers are very cooperative."

Sonam Oswal

Parent of Dhairya

★★★★★

"Modern Age Coders have wonderful teachers who teach in a clear, easy and practical way. The teacher boosts students' confidence and inspires them to learn without hesitation."

Sonu Goyal

Parent

★★★★★

"I highly recommend this computer coding class! The teachers are incredibly knowledgeable and passionate about coding."

Ritu Kedia

Parent

The rest of the Class 12 series

## More pages for Class 12 students

Every page in the CBSE Class 12 Computer Science series, grouped by what you need.

### Practicals, project and viva

- [Class 12 CS viva questions](/cbse-class-12-computer-science-viva-questions)
- [Class 12 CS project with source code](/cbse-class-12-computer-science-project-python-mysql)
- [Class 12 CS project topics](/cbse-class-12-computer-science-project-topics)

### Exam, papers and marks

- [Class 12 CS sample paper practice](/cbse-class-12-computer-science-sample-paper-2026-27)
- [Class 12 CS exam date, pattern and marks](/cbse-class-12-computer-science-paper-pattern-and-marking-scheme)
- [Class 12 CS important questions](/cbse-class-12-computer-science-important-questions)

### Questions and practice

- [Class 12 CS MCQ test](/cbse-class-12-computer-science-mcq-test)
- [Class 12 CS output questions](/cbse-class-12-computer-science-output-questions)
- [Class 12 CS case study questions](/cbse-class-12-computer-science-case-study-questions)
- [Class 12 CS SQL questions](/cbse-class-12-computer-science-sql-queries)

### Chapter by chapter

- [Functions in Python Class 12](/cbse-class-12-computer-science-functions)
- [Text file handling Class 12](/cbse-class-12-computer-science-file-handling)
- [CSV and binary files Class 12](/cbse-class-12-computer-science-csv-and-binary-files)
- [Stack Class 12 Computer Science](/cbse-class-12-computer-science-stack)
- [Computer networks Class 12](/cbse-class-12-computer-science-computer-networks)
- [Python MySQL connectivity Class 12](/cbse-class-12-computer-science-python-mysql-connectivity)

### Notes, revision and help

- [Class 12 CS syllabus 2026-27](/cbse-class-12-computer-science-syllabus-2026-27)
- [Class 12 CS notes](/cbse-class-12-computer-science-notes)
- [Class 12 CS revision plan](/cbse-class-12-computer-science-revision-plan)
- [Class 12 CS crash course](/cbse-class-12-computer-science-crash-course)

**CBSE Class 12 Informatics Practices (065):** [Class 12 IP practical file](/cbse-class-12-informatics-practices-practical-file)  [Class 12 IP project with source code](/cbse-class-12-informatics-practices-project)  [Class 12 IP sample paper practice](/cbse-class-12-informatics-practices-sample-paper-2026-27)  [Class 12 IP important questions](/cbse-class-12-informatics-practices-important-questions)

**CBSE Class 12 Information Technology (802):** [IT 802 practical and project file](/cbse-class-12-it-802-practical-and-project-file)  [IT 802 Java notes and programs](/cbse-class-12-it-802-java-programs)  [IT 802 notes](/cbse-class-12-it-802-notes)

**CBSE Class 11 CS, IP and AI:** [Class 11 CS practical file](/cbse-class-11-computer-science-practical-file)  [Class 11 IP practical file](/cbse-class-11-informatics-practices-practical-file)  [CS or IP in Class 11](/computer-science-or-informatics-practices-class-11)

**ISC Computer Science (868):** [ISC Class 12 CS syllabus 2027](/isc-class-12-computer-science-syllabus-2027)  [ISC Class 12 CS practice paper](/isc-class-12-computer-science-specimen-paper-practice)  [ISC Class 12 practical questions solved](/isc-class-12-computer-science-practical-questions)  [ISC Boolean algebra and K-maps](/isc-class-12-computer-science-boolean-algebra)

**Program lists with output:** [Class 12 CS practical file](/blog/python-practical-file-class-12)  [20 Python programs for Class 12](/blog/python-programs-for-cbse-class-12)  [Menu-driven programs in Python](/blog/how-to-build-menu-driven-program-in-python)

Questions on exceptions

## Exception handling in Class 12: questions students ask

### What is exception handling in Python Class 12?

It is writing code that deals with errors which occur while a program is running, so the program can respond and not simply stop. In CBSE 083 for 2026-27 it is done with three blocks: try for the risky statements, except for the response to a named exception, and finally for statements that run in every case.

### How many marks is exception handling in Class 12 Computer Science?

CBSE does not give the chapter separate marks. It is part of Unit 1, which carries 40 of the 70 theory marks. In the 2026-27 sample paper it is tested in a 1-mark question, and a try and except around pickle.load() earns credit inside the 5-mark binary file question.

### What is the difference between a syntax error and an exception?

A syntax error breaks a rule of Python, like leaving out a colon, and is reported before the program runs. An exception happens during the run, when a correctly written statement cannot be carried out, such as int("twelve"). Only exceptions can be handled by a try block in that program.

### Does finally run if there is a return in try?

Yes. Python works out the value to be returned, runs the finally block, and only then goes back to the caller. So anything printed in finally appears before the caller prints the returned value. The check(8) example on this page prints checked 8 first and 12 second.

### Can we use try without except in Python?

Yes, provided there is a finally block. The finally statements run and the exception then continues and stops the program, since nothing has handled it. Students use this form when a file must be closed whatever happens. A try with neither except nor finally is a syntax error.

### Are raise and assert in the CBSE Class 12 syllabus 2026-27?

The 083 line names introduction and handling exceptions using try-except-finally blocks. raise, assert and the else clause are not named in it. Many textbooks explain them, so know what each does in one sentence, and check with your teacher for school tests.

### Which exceptions are important for Class 12 CS?

ZeroDivisionError, ValueError, TypeError, NameError, IndexError, KeyError, FileNotFoundError and EOFError cover most of what a Class 12 program meets. Learn one statement that raises each. ModuleNotFoundError is worth adding, because it is what a wrongly spelt import gives.

### What is the difference between ValueError and TypeError?

TypeError means the kind of object is wrong for the operation, such as adding a string to an integer. ValueError means the kind is right but the particular value is not, such as int("abc"), where a string is accepted but this one cannot be converted.

### Why is EOFError used in binary file programs?

pickle.load() reads one record at a time and does not say how many are left. When none remain it raises EOFError. Catching that exception is the usual way to end the reading loop, so here it is a normal event and not a fault.

### Is there one to one tuition for Class 12 Python exceptions and files?

Yes. Modern Age Coders holds live one to one classes for 083 at your own days and timing. Start with a priority demo, about 45 to 60 minutes with a written skill report, and its fee is adjusted against your first month if you enrol. You may take a free demo class instead.

Start

## Paste your last error message.

In a free demo class the teacher reads that message with you: the name, the line, the cause, the fix. Ten minutes of this teaches more than a list of definitions.

The **priority demo** goes further. You choose the slot, bring one of your file programs, and spend a whole class making it safe against bad input, missing files and the end of the data. A written skill report follows, and the fee is taken off your first month if you enrol.

More programs to test yourself on: [Python programs for CBSE Class 12](/blog/python-programs-for-cbse-class-12), and [the Class 12 CS crash course](/cbse-class-12-computer-science-crash-course) if time is short.

[WhatsApp us](https://wa.me/919123366161?text=Hello%20Modern%20Age%20Coders.%20I%20want%20one%20to%20one%20help%20with%20exception%20handling%20and%20files%20in%20CBSE%20Class%2012%20Computer%20Science%20083.) · [+91 91233 66161](tel:+919123366161) · [connect@modernagecoders.com](mailto:connect@modernagecoders.com)

Every class is live video. The form requests a callback and reserves nothing.

### Want it sooner? Book a priority demo

A full live class of about 45 to 60 minutes at a slot you pick, with a written skill report and learning roadmap on WhatsApp afterwards. The fee is adjusted against your first month if you enrol.

[Book a priority demo](/book-demo)

## Keep exploring Modern Age Coders

### By class and age

- [Number System Class 11 Computer Science: Conversions, Logic](/cbse-class-11-number-system-conversion)
- [Class 11 IP Sample Paper 2026-27 With Solution, 70 Marks](/cbse-class-11-informatics-practices-sample-paper)
- [Class 11 IP Notes 2026-27: All Four Units, With Code](/cbse-class-11-informatics-practices-notes)
- [Class 11 Computer Science Sample Paper 2026-27, Solved](/cbse-class-11-computer-science-sample-paper)
- [Class 11 Computer Science Project in Python, with Topics](/cbse-class-11-computer-science-project)
- [Class 11 Computer Science Notes 2026-27, Chapter Wise](/cbse-class-11-computer-science-notes)
- [Python MySQL Connectivity Class 12: Programs and Errors](/cbse-class-12-computer-science-python-mysql-connectivity)
- [Class 12 Computer Science Marking Scheme 2027, Date, Pattern](/cbse-class-12-computer-science-paper-pattern-and-marking-scheme)
- [Class 12 Computer Science Output Questions with Answers](/cbse-class-12-computer-science-output-questions)

### Learn more

- [CS Summer Programs for High School Students: 2027 Guide](/computer-science-summer-programs-for-high-school-students)
- [GCSE Computer Science Tutoring](/uk-gcse-computer-science-tutoring)
- [GCSE Computer Science: AQA, OCR and Edexcel Exam Prep](/courses/gcse-computer-science-course)
- [IB Computer Science Online Tuition](/ib-computer-science-online-tuition)

### Free resources

- [C++ Tutorial: From Basics to Advanced](/resources/cpp)
- [Transformers and Attention Mechanism](/resources/ai-and-machine-learning/transformers-and-attention)
- [Data Preprocessing and Exploratory Data Analysis](/resources/ai-and-machine-learning/data-preprocessing-and-eda)
- [Exception Handling (try, catch, throw)](/resources/cpp/exception-handling-in-cpp)

### From the blog

- [Exception Handling in Python: Try, Except, Finally](/blog/exception-handling-in-python)
- [Python Programs for Class 11 CBSE (CS and IP) With Output](/blog/python-programs-for-class-11)
- [ICSE Class 10 Computer Applications: Revision Guide](/blog/icse-class-10-computer-applications-revision)

### Start here

- [What Modern Age Coders families say](/love)
- [Book a free demo class with Modern Age Coders](/book-demo)

---

*Canonical: https://learn.modernagecoders.com/cbse-class-12-computer-science-exception-handling*
