---
title: "What are the rules of catchable Exceptions in Try Catch blocks in Java?"  
description: "What are the rules of catchable Exceptions in Try Catch blocks in Java?"  
author: "Utpal Vishwas"  
published: 2023-07-28  
updated: 2023-07-29  
canonical: https://www.mindstick.com/forum/159350/what-are-the-rules-of-catchable-exceptions-in-try-catch-blocks-in-java  
category: "java"  
tags: ["exception handling", "java", "exception"]  
reading_time: 2 minutes  

---

# What are the rules of catchable Exceptions in Try Catch blocks in Java?

What are the [rules](https://www.mindstick.com/articles/43901/blackjack-rules) of catchable [Exceptions](https://www.mindstick.com/interview/22871/define-predifined-generic-exceptions) in [Try Catch](https://www.mindstick.com/articles/12105/exception-handling-in-java-multiple-exception-handlers) blocks in [Java](https://www.mindstick.com/articles/12214/web-development-company-in-india-laid-on-the-foundation-of-concrete-java-programming)?

## Replies

### Reply by Aryan Kumar

Sure, I can help you with that.

Here are the rules for checked exceptions in try-[catch](https://www.mindstick.com/forum/159341/how-to-use-try-and-catch-in-java-for-exception-handling-and-what-happens-when-an-exception-occurs) blocks in Java:

- **Checked exceptions must be handled or specified.** This means that if a method throws a checked exception, the method must either handle the exception or specify the exception using the `throws` keyword. If the method does not handle or specify the exception, the compiler will not allow the code to compile.
- **Checked exceptions can be caught in a try-catch block.** A try-catch block is a block of code that can be used to handle exceptions. If an exception is thrown in a try-catch block, the exception will be caught by the catch block and the code in the catch block will be executed.
- **Checked exceptions can be propagated.** Propagating an exception means that the exception is not handled in the try-catch block and is instead passed on to the calling method. The calling method can then handle the exception or propagate it further.

Here is an example of a try-catch block that handles a checked exception:

```plaintext
public void readFile(String fileName) throws IOException {
  try {
    FileInputStream fis = new FileInputStream(fileName);
    int data = fis.read();
    ...
  } catch (IOException e) {
    // Handle the exception
    System.out.println("Error reading file: " + e.getMessage());
  }
}
```

In this example, the `readFile()` method throws an `IOException` if there is an error reading the file. The try-catch block catches the `IOException` exception and prints an error message if the exception is thrown.


---

Original Source: https://www.mindstick.com/forum/159350/what-are-the-rules-of-catchable-exceptions-in-try-catch-blocks-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
