019-004-009
Rethrowing Exceptions
Medium
Problem Description
Rethrowing Exceptions
In this problem, you will implement the processNumber(String input) method. It converts the input string to an integer and returns it on success. When a NumberFormatException occurs, it prints "[LOG] Parse error occurred" and rethrows the same exception.
Learning Objective: Understand how to catch an exception, log it, then rethrow to delegate handling to a higher-level caller
Overview
After catching an exception for logging or partial processing, you can rethrow it using the throw statement. This enables both logging in intermediate methods and full handling at higher levels.
Method Signature
static int processNumber(String input)
Specifications
- Convert
inputto an integer usingInteger.parseInt() - Return the integer value on success
- On
NumberFormatException, print"[LOG] Parse error occurred"and rethrow the same exception withthrow e
Call Examples
processNumber("42") → 42 (normal)
processNumber("abc") → NumberFormatException (rethrown)
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up