Over 10 years we helping companies reach their financial and branding goals. Onum is a values-driven SEO agency dedicated.

CONTACTS
ECET 2026 CSE

Day 62 Night Mastering Java Exception Handling for ECET 2026

Concept Notes (Deep Explanation + Examples)

🔹 What is Exception Handling?

In Java, an exception is an event that interrupts the normal flow of a program. It occurs when something goes wrong during program execution — like dividing by zero, accessing an invalid array index, or opening a missing file.

To handle these unexpected events gracefully (without crashing the program), Java provides a mechanism called Exception Handling.


🔹 Why Exception Handling is Important (ECET Focus)

  • Prevents program crashes during runtime
  • Makes debugging easier
  • Ensures smooth execution even after runtime errors
  • Is frequently asked in ECET and GATE under Java Programming Fundamentals

🔹 Types of Errors in Java

  1. Compile-Time Errors → Syntax errors (e.g., missing semicolon)
  2. Runtime Errors (Exceptions) → Detected during execution
  3. Logical Errors → Wrong output but no crash

🔹 Exception Hierarchy Diagram (in words)

Throwable  
├── Exception (checked exceptions)  
│    ├── IOException  
│    ├── SQLException  
│    └── ClassNotFoundException  
└── Error (unchecked – not recoverable)
     ├── StackOverflowError  
     ├── OutOfMemoryError  
     └── VirtualMachineError  

Under Exception:

  • Checked Exceptions → must be handled (like FileNotFoundException)
  • Unchecked Exceptions → handled optionally (like NullPointerException)

🔹 Basic Syntax

try {
   // Code that might throw an exception
} catch (ExceptionType e) {
   // Handle the exception
} finally {
   // Always executed (optional)
}

🔹 Example 1: Division by Zero (Simple Example)

class DivideExample {
    public static void main(String args[]) {
        try {
            int a = 10, b = 0;
            int c = a / b;   // throws ArithmeticException
            System.out.println(c);
        } catch (ArithmeticException e) {
            System.out.println("Error: Cannot divide by zero!");
        }
        System.out.println("Program continues smoothly...");
    }
}

Output:

Error: Cannot divide by zero!
Program continues smoothly...

👉 Without exception handling, the program would crash after dividing by zero.


🔹 Example 2: Multiple Catch Blocks

try {
    int[] arr = new int[3];
    arr[5] = 10; // ArrayIndexOutOfBoundsException
} catch (ArithmeticException e) {
    System.out.println("Arithmetic error");
} catch (ArrayIndexOutOfBoundsException e) {
    System.out.println("Array index out of range");
} catch (Exception e) {
    System.out.println("General exception");
}

Output:
Array index out of range


🔹 Example 3: finally Block

try {
    int num = 10 / 0;
} catch (ArithmeticException e) {
    System.out.println("Caught exception");
} finally {
    System.out.println("Finally block always executes");
}

Output:

Caught exception  
Finally block always executes

🔹 Real-World Example (Classroom Experience)

Imagine a lab program where a student enters file names for reading data. If the file doesn’t exist, the program crashes — but with exception handling, the program instead displays:

“File not found! Please check your file name.”


🔹 ECET-Level Tip 💡

Common ECET questions revolve around:

  • Keywords (try, catch, finally, throw, throws)
  • Checked vs Unchecked exceptions
  • Output prediction based on try-catch-finally order

3️⃣ ⚙️ Formulas (Plain LaTeX, No Boxes)

Even though this topic is theoretical, some ECET logic rules can be written as expressions:

  • \text{Try Block Execution} \to \text{Catch if Exception Occurs} \to \text{Finally Always Executes}
  • \text{Number of catch blocks} \ge 1
  • \text{If no exception occurs, finally block still runs}

4️⃣ 🔟 10 MCQs (ECET + GATE Hybrid)

1️⃣ Which keyword is used to handle exceptions in Java?
A) error
B) catch
C) handle
D) final

2️⃣ Which of these is a checked exception?
A) ArithmeticException
B) NullPointerException
C) IOException
D) ArrayIndexOutOfBoundsException

3️⃣ Which block executes whether an exception occurs or not?
A) try
B) catch
C) finally
D) throw

4️⃣ What happens if an exception is not handled?
A) Program continues normally
B) Program stops execution
C) Compiler fixes it
D) JVM skips the line

5️⃣ Identify the output:

try {  
   System.out.println(10/0);  
} catch(Exception e) {  
   System.out.println("Error");  
}

A) 10
B) 0
C) Error
D) Runtime Error

6️⃣ Which keyword is used to declare an exception in method signature?
A) final
B) throw
C) throws
D) catch

7️⃣ Which of these cannot be caught?
A) ArithmeticException
B) IOException
C) Error
D) NullPointerException

8️⃣ In which block should resource closing code be written?
A) try
B) catch
C) finally
D) throw

9️⃣ Which of the following is NOT an exception?
A) SQLException
B) OutOfMemoryError
C) ArithmeticException
D) IOException

🔟 Output of:

try {
    int a = 5/0;
} finally {
    System.out.println("Done");
}

A) Done
B) Error
C) Done + Error
D) Compilation error


5️⃣ ✅ Answer Key (WordPress Table — NO HTML)

Q No | Answer
1 | B
2 | C
3 | C
4 | B
5 | C
6 | C
7 | C
8 | C
9 | B
10 | C


6️⃣ 🧠 MCQ Explanations

1️⃣ B – catch → Used for handling exceptions; try detects, catch handles.
2️⃣ C – IOException → Checked exception; must be handled using try-catch or declared with throws.
3️⃣ C – finally → Always executes whether exception occurs or not.
4️⃣ B – Program stops execution → JVM terminates the program if exception isn’t handled.
5️⃣ C – Error → ArithmeticException caught by catch block prints “Error”.
6️⃣ C – throws → Declares that a method may throw exceptions.
7️⃣ C – Error → Errors are not caught as they are not recoverable.
8️⃣ C – finally → Best place for closing files, releasing resources.
9️⃣ B – OutOfMemoryError → It’s an Error, not an Exception.
10️⃣ C – Done + Error → finally executes, then program throws ArithmeticException.


7️⃣ 🎯 Motivation (ECET 2026 Specific)

Exception Handling appears almost every year in ECET CSE section — especially in output prediction and keyword usage questions.
Understanding this topic not only secures 2–4 marks easily, but also boosts your Java programming clarity — crucial for GATE & placement coding rounds.
👉 Be consistent — even 30 minutes of Java practice daily improves confidence drastically!


8️⃣ 📲 CTA (Fixed)

Join our ECET 2026 CSE WhatsApp Group for daily quizzes & study notes:
https://chat.whatsapp.com/GniYuv3CYVDKjPWEN086X9

Leave a comment

Your email address will not be published. Required fields are marked *