Multiple Catch Block in Java — Java Technical Interview Questions & Answers

Multiple Catch Block in Java

Multiple Catch Block in Java

  • Multiple Catch Block sits inside exception handling. try holds risky code. catch runs backup code. finally runs cleanup (close file / connection) whether error happened or not.
  • throw sends an exception. throws declares a checked exception on the method. Empty catch blocks hide bugs — print or log the message.
  • Checked exceptions must be handled or declared. Unchecked (RuntimeException family) usually are not declared. Catch specific types first, then broader ones.
  • Let's take this on the board with one tiny Main class — no extra files. Output: Asha scored 72 then Pass. Real Main. Swap marks/name to show one idea from Multiple Catch Block in Java. Start from main, go line by line, and stop at each print. That output is the proof for Multiple Catch Block.

Technical Interview Tip: Explain Multiple Catch Block in Java as: definition → why → one code idea.

Code Examples for Multiple Catch Block in Java

Example

// Multiple
public class Main {
  public static void main(String[] args) {
    int marks = 72;
    String name = "Asha";
    System.out.println(name + " scored " + marks);
    if (marks >= 40) System.out.println("Pass");
  }
}

Output: Asha scored 72 then Pass. Real Main. Swap marks/name to show one idea from Multiple Catch Block in Java.

How to Explain Multiple Catch Block in Java to an Interviewer

What is Multiple Catch Block?

try = risky code. catch = backup. finally = cleanup always. throw = do it. throws = declare it on the method. checked = handle or declare. unchecked = RuntimeException family.

Why do we use Multiple Catch Block in Java?

Makes the program clearer or safer try = risky code. catch = backup. finally = cleanup always.

Write one small example of Multiple Catch Block.

Show syntax Say what prints

What mistake do beginners make with Multiple Catch Block?

Only the name, no example Empty catch hides the real bug.

Where is Multiple Catch Block used in a real program?

Day-to-day Java code