Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
School/C# - Beginner (Denis)/Lesson 44/lesson_44.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
57 lines (49 sloc)
986 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
catch | |
{ | |
// выполняемые инструкции | |
} | |
catch (тип_исключения) | |
{ | |
// выполняемые инструкции | |
} | |
try | |
{ | |
int x = 5; | |
int y = x / 0; | |
Console.WriteLine($"Результат: {y}"); | |
} | |
catch (DivideByZeroException) | |
{ | |
Console.WriteLine("Возникло исключение DivideByZeroException"); | |
} | |
catch (тип_исключения имя_переменной) | |
{ | |
// выполняемые инструкции | |
} | |
try | |
{ | |
int x = 5; | |
int y = x / 0; | |
Console.WriteLine($"Результат: {y}"); | |
} | |
catch (DivideByZeroException ex) | |
{ | |
Console.WriteLine($"Возникло исключение {ex.Message}"); | |
} | |
catch when (условие) | |
{ | |
} | |
int x = 1; | |
int y = 0; | |
try | |
{ | |
int result = x / y; | |
} | |
catch (DivideByZeroException) when (y == 0 && x == 0) | |
{ | |
Console.WriteLine("y не должен быть равен 0"); | |
} | |
catch (DivideByZeroException ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} |