Skip to content

Commit 75c518c

Browse files
committed
add traps
1 parent a0d7f9a commit 75c518c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

platform-includes/capture-error/powershell.mdx

+14
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,17 @@ catch
1010
$_ | Out-Sentry
1111
}
1212
```
13+
14+
Or you can install a `trap` in a block to log errors that occur within that block.
15+
Be sure to understand how `trap` works especially in regards to scope and how the execution continues/breaks when `trap` is used.
16+
17+
```powershell
18+
AFunctionThatMightFail
19+
20+
# The trap will get called even if it is declared after the code that throws.
21+
# It's because traps are processed by PowerShell before the script is executed.
22+
trap
23+
{
24+
$_ | Out-Sentry
25+
}
26+
```

0 commit comments

Comments
 (0)