Зміст курсу
Introduction to .NET with C#
Introduction to .NET with C#
Dealing 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 thecatch
block in case the parsing fails; - We can enclose the
try-catch
block into an infinitewhile
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.
Дякуємо за ваш відгук!