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 | Introduction
course content

Зміст курсу

Introduction to .NET with C#

Dealing with Exceptions caused by User InputDealing 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?

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

Виберіть правильну відповідь

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

Виберіть правильну відповідь

Все було зрозуміло?

Секція 1. Розділ 5
course content

Зміст курсу

Introduction to .NET with C#

Dealing with Exceptions caused by User InputDealing 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?

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

Виберіть правильну відповідь

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

Виберіть правильну відповідь

Все було зрозуміло?

Секція 1. Розділ 5
some-alt