Загрузка страницы

Handling Errors in PowerShell with Try..Catch..Finally

The try..catch..finally statements in PowerShell allow you to handle exceptions (errors) in your scripts. One of the unique concepts in PowerShell exceptions is the notion of a terminating error versus a non-terminating error. In this video, we'll explore the difference between both types of exceptions, and learn how to effectively use try..catch..finally to handle exceptions in a calculated manner. In addition, we'll take a look at how to use multiple catch blocks to handle specific types of errors uniquely.

The $ErrorActionPreference variable can be used to control the behavior of PowerShell cmdlets, when an exception is thrown. By setting $ErrorActionPreference to 'stop', you can change non-terminating errors into terminating errors. Only terminating errors are caught by the "try" block, so if you're struggling with a script where try..catch isn't working correctly, you might want to ensure that you're considering terminating versus non-terminating errors as a potential problem.

Microsoft Documentation for PowerShell's try..catch..finally statement: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_try_catch_finally?view=powershell-7

Producer: Trevor Sullivan
Website: https://trevorsullivan.net
Patreon: https://patreon.com/trevorsullivan
Twitter: https://twitter.com/pcgeek86
Gab: https://gab.ai/trevors

Intro music "Amen Tune" used, with permission, from Aaron Static. Check out his music here: https://soundcloud.com/aaronstatic

#DevOps #PowerShell #VSCode

Видео Handling Errors in PowerShell with Try..Catch..Finally канала Trevor Sullivan
Показать
Комментарии отсутствуют
Введите заголовок:

Введите адрес ссылки:

Введите адрес видео с YouTube:

Зарегистрируйтесь или войдите с
Информация о видео
3 февраля 2020 г. 2:49:30
00:18:48
Яндекс.Метрика