# \`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.

![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.](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/48d1bd3ebeaf48f5a144bbe3186a55a7.webp)

- Category: PowerShell
- Level: Journeyman
- Tags: and-psitem, exit-code, finally-block, powershell, TRY...CATCH
- Updated: November 10, 2026

Source: https://www.ask-codey.com/cheat-sheets/powershell-try-catch-cheat-sheet
