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

Conteúdo do Curso

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?

Selecione a resposta correta

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

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

Selecione a resposta correta

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 5
We're sorry to hear that something went wrong. What happened?
some-alt