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
foreach($hin$MyInvocation.MyCommand.Parameters.GetEnumerator()) {
try {
$key=$h.Key$val=Get-Variable-Name $key-ValueOnly -ErrorAction Stop
if (([String]::IsNullOrEmpty($val) -and (!$PSBoundParameters.ContainsKey($key)))) {
throw"A blank value that wasn't supplied by the user."
}
$params[$key] =$val
} catch {}
}
is using exceptions in a bad way (tsk tsk). This has some nasty side effects.
First, if pollutes the $Error variable, which is a bad thing for anyone who wants to use it.
I think I could work around this by something like $Error.RemoveAt(0) in the snippet's catch block.
The other problem I only just noticed in using automatic transcription. All of those errors show up as lines in the transcript, like so:
PS>TerminatingError(Get-Variable): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot find a variable with the name 'Verbose'."
>> TerminatingError(Get-Variable): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot find a variable with the name 'Debug'."
>> TerminatingError(Get-Variable): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot find a variable with the name 'ErrorAction'."
>> TerminatingError(Get-Variable): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot find a variable with the name 'WarningAction'."
>> TerminatingError(Get-Variable): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot find a variable with the name 'InformationAction'."
>> TerminatingError(Get-Variable): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot find a variable with the name 'ErrorVariable'."
>> TerminatingError(Get-Variable): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot find a variable with the name 'WarningVariable'."
>> TerminatingError(Get-Variable): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot find a variable with the name 'InformationVariable'."
>> TerminatingError(Get-Variable): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot find a variable with the name 'OutVariable'."
>> TerminatingError(Get-Variable): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot find a variable with the name 'OutBuffer'."
>> TerminatingError(Get-Variable): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot find a variable with the name 'PipelineVariable'."
>> TerminatingError(Get-Variable): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot find a variable with the name 'WhatIf'."
>> TerminatingError(Get-Variable): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Cannot find a variable with the name 'Confirm'."
This really sucks.
I'd like to rewrite the snippet in a way that doesn't (ab)use exceptions, to solve both problems.
The text was updated successfully, but these errors were encountered:
This snippet to discover the parameters:
is using exceptions in a bad way (tsk tsk). This has some nasty side effects.
First, if pollutes the
$Error
variable, which is a bad thing for anyone who wants to use it.I think I could work around this by something like
$Error.RemoveAt(0)
in the snippet'scatch
block.The other problem I only just noticed in using automatic transcription. All of those errors show up as lines in the transcript, like so:
This really sucks.
I'd like to rewrite the snippet in a way that doesn't (ab)use exceptions, to solve both problems.
The text was updated successfully, but these errors were encountered: