5
私はC#で書かれた次のコマンドレットは、それは基本的には、エラーがスローされますがあります。ThrowTerminatingErrorはどのようにC#で動作しますか?
[Cmdlet("Use", "Dummy")]
public class UseDummyCmdlet :PSCmdlet
{
protected override void ProcessRecord()
{
var errorRecord = new ErrorRecord(new Exception("Something Happened"), "SomethingHappened", ErrorCategory.CloseError, null);
ThrowTerminatingError(errorRecord);
}
}
私は(私が間違っている可能性)と仮定している、これはPowerShellのと同等です)
Function Use-Dummy()
{
[CmdletBinding()]
Param()
process
{
$errorRecord = New-Object System.Management.Automation.ErrorRecord -ArgumentList (New-Object System.Exception), 'SomethingHappened', 'NotSpecified', $null
$PSCmdlet.ThrowTerminatingError($errorRecord)
}
}
Use-Dummy : Exception of type 'System.Exception' was thrown.
At line:1 char:10
+ use-dummy <<<<
+ CategoryInfo : NotSpecified: (:) [Use-Dummy], Exception
+ FullyQualifiedErrorId : SomethingHappened,Use-Dummy
しかしC#バージョン、クラッシュし、次の情報:PowerShellのバージョンが期待どおりに動作し
An exception of type 'System.Management.Automation.PipelineStoppedException' occurred in System.Management.Automation.dll but was not handled in user code
Additional information: The pipeline has been stopped.
私は間違っていますか?
あなたは何を期待しましたか? C#はスクリプト言語ではありません。処理されない例外が発生すると、プログラムがクラッシュします。 –
私は同じ出力が期待されます。コードはちょうど異なる言語でちょうど同じことをします。どちらもPowerShellで実行できますが、PowerShellバージョンではなくC#バージョンを実行しているときにパイプラインが突然閉じられる理由を知りたいだけです。 – Jake
このコマンドレットはどのように使用しますか?それはモジュール/スナップインか動的に追加されていますか?どのように呼びますか? PowerShellコンソール、ISE、別のアプリケーションからですか? 「クラッシュ」とはどういう意味ですか? –