Share via


ILanguageExceptionErrorInfo2::CapturePropagationContext 메서드(restrictederrorinfo.h)

언어 경계 및 스레드 간에 예외의 컨텍스트를 캡처합니다.

구문

HRESULT CapturePropagationContext(
  [in] IUnknown *languageException
);

매개 변수

[in] languageException

프로세스에서 아파트-agile, in-proc 및 marshal-by-value인 오류 개체입니다.

반환 값

메서드가 성공하면 S_OK를 반환하고, 그러지 않으면 HRESULT 오류 코드를 반환합니다.

설명

CapturePropagationContext 는 오류를 다시 throw할 때 언어 프로젝션에 의해 활용됩니다. 여기에는 언어 경계에서 오류가 수신되는 경우가 포함됩니다. 따라서 CapturePropagationContext 를 활용하면 예외에 대한 백 추적이 현재 다시 throw에 대해 캡처되도록 할 수 있습니다. 이는 예외가 언어 경계를 넘을 때 관련 디버깅 정보가 손실되지 않도록 하기 위한 것입니다.

일반적으로 메서드는 예외가 전파되는 방법에 대한 추가 오류 정보를 제공하는 IRestrictedErrorInfo 개체의 연결된 목록을 만듭니다. 이 정보는 크래시 덤프 분석 중에 예외 레코드에서 참조하는 보관된 예외로 노출됩니다. 이 연결된 목록을 사용하여 오류가 발생한 위치를 포함하여 예외가 전파된 모든 언어 경계 및 스레드에 대한 백 추적을 관찰할 수 있습니다.

예제

다음 예제에서는 다른 프로젝션 또는 WRL에서 해당 언어 경계에서 오류를 수신하는 프로젝션을 보여 줍니다. 이 시나리오는 기존 시나리오이지만 이전 프로젝션을 수행할 수 없는 경우 시스템에서 추가 컨텍스트를 캡처할 수 있습니다.

HRESULT CreateFooExceptionFromLanguageBoundaryError(HRESULT errorReceived, IFooException** createdException)
{
    HRESULT hr = S_OK;
    ComPtr<IFooException> exception;
    // Get the current error
    ComPtr<IRestrictedErrorInfo> restrictedErrorInfo;
    *createdException = nullptr;
    if (SUCCEEDED(GetRestrictedErrorInfo(&restrictedErrorInfo)))
    {
        // Retrieve details regarding the error to determine if it is a stale error
        // or if it is the error we received at the boundary.
        BSTR description;
        HRESULT errorOriginated;
        BSTR restrictedDescription;
        BSTR capabilitySid;
        hr = restrictedErrorInfo->GetErrorDetails(
            &description,
            &errorOriginated,
            &restrictedDescription,
            &capabilitySid);
        if (SUCCEEDED(hr) && errorReceived == errorOriginated)
        {
            hr = CreateFooException(
                errorOriginated,
                restrictedDescription,
                restrictedErrorInfo.Get(),
                &exception);
            // Query for new interface to see if the new logic is there to
            // capture the current propagation context.
            ComPtr<ILanguageExceptionErrorInfo2> languageExceptionErrorInfo;
            if (SUCCEEDED(restrictedErrorInfo.As(&languageExceptionErrorInfo)))
            {
                languageExceptionErrorInfo->CapturePropagationContext(nullptr);
            }		
            *createdException = exception.Detach();
            SetRestrictedErrorInfo(restrictedErrorInfo.Get());
            SysFreeString(description);
            SysFreeString(restrictedDescription);
            SysFreeString(capabilitySid);
            return hr;
        }
        SysFreeString(description);
        SysFreeString(restrictedDescription);
        SysFreeString(capabilitySid);
    }

    // We are here if the error didn't match or we couldn't get error details.
    // So originate a new error.
    // OriginateErrorInfoForThrow will call RoOriginateLanguageException, which will      
    // capture the context
    hr = CreateFooException(errorReceived, nullptr, nullptr, &exception);
    if(SUCCEEDED(hr))
    {
        exception->OriginateErrorInfoForThrow();
        *createdException = exception.Detach();
    }
    return hr;
}


요구 사항

요구 사항
지원되는 최소 클라이언트 Windows 10 버전 1703 [데스크톱 앱만 해당]
지원되는 최소 서버 Windows Server 2016 [데스크톱 앱만 해당]
대상 플랫폼 Windows
헤더 restrictederrorinfo.h

추가 정보

ILanguageExceptionErrorInfo2