Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
学ぶ Dealing with Exceptions caused by User Input | Section
Introduction to .NET with C#

bookDealing with Exceptions caused by User Input

メニューを表示するにはスワイプしてください

Recap:

  • try-catch blocks can be used for avoiding program crashes in case of invalid inputs;
  • The code that parses user input can be enclosed into a try block, and an error message can be displayed to the user via the catch block in case the parsing fails;
  • We can enclose the try-catch block into an infinite while loop, 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?

question mark

In a try-catch structure, where should the code that might throw an exception be placed?

正しい答えを選んでください

question mark

What will happen if the user enters "abc" when prompted?

正しい答えを選んでください

すべて明確でしたか?

どのように改善できますか?

フィードバックありがとうございます!

セクション 1.  5

AIに質問する

expand

AIに質問する

ChatGPT

何でも質問するか、提案された質問の1つを試してチャットを始めてください

セクション 1.  5
some-alt