← Back to Exceptions
Question 757
Fallback Value On Parse Error
Fallback Value On Parse Error
Declareint n;. Read a line and try to parse it inton. If parsing throws aFormatException, setn = 0instead. After the try/catch, printValue is <n>. This shows using a catch to recover and keep running. Use top-level statements. Input42prints: Value is 42 Inputoopsprints: Value is 0
Expected Output:
Value is 42= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
Exceptions
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.