← All Exercises
Java Try-Catch Exception Handling
basicjava
Background
Java exceptions provide structured error handling with checked and unchecked exception types.
Problem
Write a Java method that parses a string to integer and divides 100 by it, handling NumberFormatException and ArithmeticException.
Input
A string that should contain a non-zero integer.
Output
The result of 100/n, or an error message string.
Sample tests
Sample 1
Input: "5"
Expected: 20
Your solution
Learning objective
Learn try-catch with multiple catch clauses, exception types, and error message patterns.