-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Everything you want to know about try catch throw except for that one thing #8332
Description
throw "some message"
catch {
access thrown text how exactly?
}
Not a complicated thing - pretty straight forward everywhere you see try / catch / throw - but not for MS. On the page that claims to give all the answers this one small commonly used detail is omitted. I grant it may be embedded somewhere in the text - but it is the age old gripe - make me read pages and pages of text to find that one small thing I need which is not that an uncommon request.
A simple
try {
throw "Oops"
} catch {
Write-Host $Error[0]
}
Would have cleared this up nicely - but not a mention of it on the page - but this is the page that tells us EVERYTHING we need to know about try / catch / throw
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 2d17c2d6-c661-1ac1-0448-5ab8b93d3215
- Version Independent ID: c6fcadc7-ba97-bd14-6a24-45617b102b32
- Content: Everything you wanted to know about exceptions - PowerShell
- Content Source: reference/docs-conceptual/learn/deep-dives/everything-about-exceptions.md
- Product: powershell
- Technology: powershell-conceptual
- GitHub Login: @sdwheeler
- Microsoft Alias: sewhee