← Back to Exceptions
Question 677
Convert.ToInt32 Can Throw Too
Convert.ToInt32 Can Throw Too
Read a line and convert it withConvert.ToInt32, then printDoubled: <n*2>. Likeint.Parse,Convert.ToInt32throws aFormatExceptionon invalid text — catch it and print exactlyInvalid integer. Use top-level statements withtry/catch. Input6prints: Doubled: 12 Inputabcprints: Invalid integer
Expected Output:
Doubled: 12
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.