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
Introduction to .NET with C#
course content

Зміст курсу

Introduction to .NET with C#

Introduction to .NET with C#

1. Introduction
2. Asynchronous Programming and Introduction to Web Services
3. Introduction to Databases with .NET
4. CRUD Operations with MySQL
5. Optimizing Database Operations

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?
In a try-catch structure, where should the code that might throw an exception be placed?

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?

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

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

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

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 5
We're sorry to hear that something went wrong. What happened?
some-alt