You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use "throw ..." instead of "Write-Error ...; Exit 1"
Write-Error is (almost) a no-op inside methods. It currently works
inside void methods but it's a bug, not an intentional feature.
See PowerShell/PowerShell#5331 and PowerShell/PowerShell#9702
Also, "throw" is more correct semantically.
Copy file name to clipboardExpand all lines: psperl.ps1
+3-6Lines changed: 3 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -13,8 +13,7 @@ param (
13
13
# Make sure we only attempt to work for PowerShell v5 and greater
14
14
# this allows the use of classes.
15
15
if ($PSVersionTable.PSVersion.Major-lt5) {
16
-
Write-Error"PowerShell v5.0+ is required for psperl. https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell?view=powershell-6";
17
-
exit
16
+
throw"PowerShell v5.0+ is required for psperl. https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell?view=powershell-6";
# if nothing is found, a null thingy is returned. This can be tested with a simple truthiness test
100
99
if (-Not$found) {
101
-
Write-Error("No installable version of Perl found by the name $($install). Try `psperl -available` to get a list of available perl installations.");
102
-
exit(1);
100
+
throw"No installable version of Perl found by the name $($install). Try `"psperl -available`" to get a list of available perl installations.";
103
101
}
104
102
# check to see if we got just one.
105
103
if ($found-is'System.Object') {
106
104
$psperl.Install($found);
107
105
}
108
106
else {
109
-
Write-Error("Unexpected results $($found.GetType()) searching for $($install). Try `psperl -available` to get a list of available perl installations.");
110
-
exit(1);
107
+
throw"Unexpected results `"$($found.GetType())`" searching for `"$($install)`". Try `"psperl -available`" to get a list of available perl installations.";
0 commit comments