`try`, `catch` and `finally`

try runs your lines, catch runs only if one of them hits an error that stops it (which -ErrorAction Stop arranges), $_ in catch is the error, so you can tell the user what happened and what to do, and finally runs whatever happens.

Updated

Cheat sheet for the lesson `try`, `catch` and `finally`: try runs your lines, catch runs only if one of them hits an error that stops it (which -ErrorAction Stop arranges), $_ in catch is the error, so you can tell the user what happened and what to do, and finally runs whatever happens.
Category
PowerShell
Level
Journeyman
Tags
and-psitem, exit-code, finally-block, powershell, TRY...CATCH