-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathFunctionErrorHandlingExamples.ps1
More file actions
81 lines (81 loc) · 1.7 KB
/
FunctionErrorHandlingExamples.ps1
File metadata and controls
81 lines (81 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
function With-Return {
try {
Write-Host "With a return "
1 / 0
}
catch {
Write-Output "I hit the catch"
Return
}
Write-Output "I don't run this code"
}
function With-Continue {
try {
Write-Output "With a continue "
1 / 0
}
catch {
Write-Output "I hit the catch"
Continue
}
Write-Output "I do run this code"
}
function WithOut-Continue {
try {
Write-Output "Without a continue "
1 / 0
}
catch {
Write-Output "I hit the catch"
}
Write-Output "I do run this code"
}
function With-Returnloop {
1..10 | ForEach-Object {
try {
Write-Host "With a return $Psitem"
if ($psitem -eq 4) {
1 / 0
}
}
catch {
Write-Output "I hit the catch $Psitem"
}
Write-Output "$Psitem I do run this code"
}
}
function With-Continueloop {
1..10 | ForEach-Object {
try {
Write-Host "With a contiue $Psitem"
if ($psitem -eq 4) {
1 / 0
}
}
catch {
Write-Output "I hit the catch $Psitem"
Continue
}
Write-Output "$Psitem I do run this code"
}
}
function WithOut-Continueloop {
1..10 | ForEach-Object {
try {
Write-Host "Without a continue $Psitem"
if ($psitem -eq 4) {
1 / 0
}
}
catch {
Write-Output "I hit the catch $Psitem"
}
Write-Output "$Psitem I do run this code"
}
}
With-Return
With-Continue
WithOut-Continue
With-Returnloop
With-Continueloop
WithOut-Continueloop