종료 오류

이 항목에서는 종료 오류를 보고하는 데 사용되는 방법에 대해 설명합니다. 또한 cmdlet 내에서 메서드를 호출하는 방법을 설명하고, 메서드가 호출될 때 Windows PowerShell 런타임에서 반환할 수 있는 예외에 대해 설명합니다.

종료 오류가 발생하면 cmdlet은 System.Management.Automation.Cmdlet.ThrowTerminatingError* 메서드를 호출하여 오류를 보고해야 합니다. 이 메서드를 사용하면 cmdlet에서 종료 오류를 발생시킨 조건을 설명하는 오류 레코드를 보낼 수 있습니다. 오류 레코드에 대한 자세한 내용은 Windows PowerShell 오류 레코드 참조하세요.

System.Management.Automation.Cmdlet.ThrowTerminatingError* 메서드가 호출되면 Windows PowerShell 런타임은 파이프라인 실행을 영구적으로 중지하고 System.Management.Automation.PipelineStoppedException 예외를 throw합니다. System.Management.Automation.Cmdlet.WriteObject , System.Management.Automation.Cmdlet.WriteError호출하거나 다른 여러 API를 호출하려고 하면 해당 호출이 System.Management.Automation.PipelineStoppedException 예외를 throw합니다.

System.Management.Automation.PipelineStoppedException 예외는 파이프라인의 다른 cmdlet이 종료 오류를 보고하거나, 사용자가 파이프라인을 중지하도록 요청했거나, 어떤 이유로든 완료되기 전에 파이프라인이 중단된 경우에도 발생할 수 있습니다. cmdlet은 열려 있는 리소스 또는 내부 상태를 정리해야 하는 경우가 아니면 System.Management.Automation.PipelineStoppedException 예외를 catch할 필요가 없습니다.

Cmdlet은 종료 오류를 보고하기 전에 여러 출력 개체 또는 종료하지 않는 오류를 작성할 수 있습니다. 그러나 종료 오류는 파이프라인을 영구적으로 중지하며 추가 출력, 종료 오류 또는 종료되지 않는 오류를 보고할 수 없습니다.

cmdlet은 System.Management.Automation.Cmdlet.BeginProcess를 호출한 스레드에서만 system.Management.Automation.Cmdlet.ThrowTerminatingError* 호출할 수 있습니다., System.Management.Automation.Cmdlet.ProcessRecord또는 System.Management.Automation.Cmdlet.EndProcessing 입력 처리 방법입니다. 다른 스레드에서 system.Management.Automation.Cmdlet.ThrowTerminatingError* 또는 System.Management.Automation.Cmdlet.WriteError 호출하지 마세요. 대신 오류를 주 스레드로 다시 전달해야 합니다.

cmdlet은 system.Management.Automation.Cmdlet.BeginProcessing , System.Management.Automation.Cmdlet.ProcessRecord또는 System.Management.Automation.Cmdlet.EndProcessing 메서드의 구현에서 예외를 throw할 수 있습니다. 이러한 메서드에서 throw된 예외(Windows PowerShell 호스트를 중지하는 몇 가지 심각한 오류 조건 제외)는 파이프라인을 중지하는 종료 오류로 해석되지만 전체 Windows PowerShell은 아닙니다. (기본 cmdlet 스레드에만 적용됩니다. 일반적으로 cmdlet에서 생성한 스레드의 catch되지 않은 예외는 Windows PowerShell 호스트를 중지합니다.) 오류 레코드는 최종 사용자에게 유용한 오류 조건에 대한 추가 정보를 제공하기 때문에 예외를 throw하는 대신 System.Management.Automation.Cmdlet.ThrowTerminatingError* 사용하는 것이 좋습니다. Cmdlet은 모든 예외(catch (Exception e))를 catch하고 처리하지 않도록 관리 코드 지침을 준수해야 합니다. 알려진 형식과 예상 형식의 예외만 오류 레코드로 변환합니다.

또한 참조하십시오

System.Management.Automation.Cmdlet.BeginProcessing

system.Management.Automation.Cmdlet.EndProcessing

System.Management.Automation.Cmdlet.ProcessRecord

System.Management.Automation.PipelineStoppedException

system.Management.Automation.Cmdlet.ThrowTerminatingError*

System.Management.Automation.Cmdlet.WriteError

Windows PowerShell 오류 레코드

Windows PowerShell Cmdlet 작성