- Популярные видео
- Авто
- Видео-блоги
- ДТП, аварии
- Для маленьких
- Еда, напитки
- Животные
- Закон и право
- Знаменитости
- Игры
- Искусство
- Комедии
- Красота, мода
- Кулинария, рецепты
- Люди
- Мото
- Музыка
- Мультфильмы
- Наука, технологии
- Новости
- Образование
- Политика
- Праздники
- Приколы
- Природа
- Происшествия
- Путешествия
- Развлечения
- Ржач
- Семья
- Сериалы
- Спорт
- Стиль жизни
- ТВ передачи
- Танцы
- Технологии
- Товары
- Ужасы
- Фильмы
- Шоу-бизнес
- Юмор
Throw Exceptions on Purpose | Metrik Rule
Last time we caught exceptions. This time we throw them ourselves — and that changes everything about how you write defensive, trustworthy code.
We start with a BankAccount that silently accepts a deposit of negative $500 and quietly corrupts its own state. That's the problem. The fix isn't a comment or a no-op. It's a throw: immediate, specific, and impossible to miss. We walk through the four exception types you'll reach for most — ArgumentException, ArgumentNullException, ArgumentOutOfRangeException, and InvalidOperationException — and how to pick the right one for each situation. Then we cover guard clauses: the pattern that puts all your validation up front and leaves the main logic clean and flat.
The second half covers custom exceptions — when a domain-specific error is important enough that callers need to catch it separately. You'll see exactly how a custom exception class works (it's just a class that inherits from Exception, using constructor chaining you already know), and how the type of the exception becomes part of the method's contract. We also cover the rethrow gotcha that trips up experienced developers: throw; and throw ex; look nearly identical but do completely different things. One preserves the original stack trace. One destroys it.
🎵 Sound effects and background music: https://nomadicsound.org
This is part of the Computer Science I with C# series on the Metrik Rule channel.
Видео Throw Exceptions on Purpose | Metrik Rule канала Metrik Rule
We start with a BankAccount that silently accepts a deposit of negative $500 and quietly corrupts its own state. That's the problem. The fix isn't a comment or a no-op. It's a throw: immediate, specific, and impossible to miss. We walk through the four exception types you'll reach for most — ArgumentException, ArgumentNullException, ArgumentOutOfRangeException, and InvalidOperationException — and how to pick the right one for each situation. Then we cover guard clauses: the pattern that puts all your validation up front and leaves the main logic clean and flat.
The second half covers custom exceptions — when a domain-specific error is important enough that callers need to catch it separately. You'll see exactly how a custom exception class works (it's just a class that inherits from Exception, using constructor chaining you already know), and how the type of the exception becomes part of the method's contract. We also cover the rethrow gotcha that trips up experienced developers: throw; and throw ex; look nearly identical but do completely different things. One preserves the original stack trace. One destroys it.
🎵 Sound effects and background music: https://nomadicsound.org
This is part of the Computer Science I with C# series on the Metrik Rule channel.
Видео Throw Exceptions on Purpose | Metrik Rule канала Metrik Rule
Комментарии отсутствуют
Информация о видео
14 мая 2026 г. 5:26:28
00:10:46
Другие видео канала
