# try Block

A block containing code that may throw an exception.

## What is **try Block** in Java?

**try Block** — A block containing code that may throw an exception.

```java
class OrderReader {
    int readQuantity(String text) {
        try {
            return Integer.parseInt(text);
        } catch (NumberFormatException error) {
            return 0;
        } finally {
            closeReader();
        }
    }

    void closeReader() {
    }
}
```

Level: Journeyman · [More Java terms at this level](https://www.ask-codey.com/glossary/subjects/java/journeyman)

Updated: September 27, 2026

## In other subjects

- [try Block in C#](https://www.ask-codey.com/glossary/try-block-c-sharp)
- [try Block in JavaScript](https://www.ask-codey.com/glossary/try-block-javascript)

Source: https://www.ask-codey.com/glossary/try-block
