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
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
Показать
Комментарии отсутствуют
Информация о видео
Другие видео канала
PowerShell Errors and Exceptions HandlingPowerShell 5.0 Classes :: All About Object ConstructorsSetting up Visual Studio Code for PowerShell DevelopmentLearn Docker in 12 Minutes 🐳Copy, Move, Delete files with PowerShellImplementing AWS Step Functions with Lambda and PowerShell Activity Taskstry, catch, finally, throw - error handling in JavaScriptPowerShell String ManipulationMicroNuggets: PowerShell Error Handling ExplainedPowerShell: Robocopy with Custom Progress BarLearn and use PowerShell with just three commandsUsing Try/Catch Blocks In PowerShellPowerShell 2020: State of the Art / Hack / Infection - SANS@Mic Keynote Network SecurityWorking with the PowerShell PipelineHandling Errors & Improving the Project Setup | Creating a REST API with Node.jsError Handling in the Real World - Portland Python User GroupDebugging PowerShell Modules with Pester Unit Tests in Visual Studio CodeHow to use PowerShell Try, Catch and the Write-Verbose and Write-DebugDetecting Text Patterns with PowerShell Regular ExpressionsTry Catch Java Tutorial