Dealing with Exceptions caused by User Input
ã¡ãã¥ãŒã衚瀺ããã«ã¯ã¹ã¯ã€ãããŠãã ãã
Recap:
try-catchblocks can be used for avoiding program crashes in case of invalid inputs;- The code that parses user input can be enclosed into a
tryblock, and an error message can be displayed to the user via thecatchblock in case the parsing fails; - We can enclose the
try-catchblock into an infinitewhileloop, which breaks after the user input is successfully parsed and stored. This way, we can make sure that instead of crashing, the program prompts the user for input until the user gives the correct input.
1. In a try-catch structure, where should the code that might throw an exception be placed?
2. What will happen if the user enters "abc" when prompted?
ãã¹ãŠæç¢ºã§ãããïŒ
ãã£ãŒãããã¯ããããšãããããŸãïŒ
ã»ã¯ã·ã§ã³Â 1. ç« Â 5
AIã«è³ªåãã
AIã«è³ªåãã
äœã§ã質åããããææ¡ããã質åã®1ã€ã詊ããŠãã£ãããå§ããŠãã ãã