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つを試してチャットを始めてください
セクション 1. 章 5