โ Back to Exceptions
Question 667
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
Topics:
Exceptions
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท 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.