โ Back to Exceptions
Question 678
Recover With a Default Value
Recover With a Default Value
Try to parse the input into a variable namedvalue. If parsing throws aFormatException, recover by settingvalueto-1inside the catch. After thetry/catch, printValue: <value>. Use top-level statements withtry/catch. Input42prints: Value: 42 Inputxyzprints: Value: -1
Expected Output:
Value: 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.