/// <summary> /// Attach restricted error information to the exception if it may apply to that exception, returning /// back the input value /// </summary> public static Exception AttachRestrictedErrorInfo(Exception e) { // If there is no exception, then the restricted error info doesn't apply to it if (e != null) { try { // Get the restricted error info for this thread and see if it may correlate to the current // exception object. Note that in general the thread's IRestrictedErrorInfo is not meant for // exceptions that are marshaled Windows.Foundation.HResults and instead are intended for // HRESULT ABI return values. However, in many cases async APIs will set the thread's restricted // error info as a convention in order to provide extended debugging information for the ErrorCode // property. IRestrictedErrorInfo restrictedErrorInfo = UnsafeNativeMethods.GetRestrictedErrorInfo(); if (restrictedErrorInfo != null) { string description; string restrictedDescription; string capabilitySid; int restrictedErrorInfoHResult; restrictedErrorInfo.GetErrorDetails(out description, out restrictedErrorInfoHResult, out restrictedDescription, out capabilitySid); // Since this is a special case where by convention there may be a correlation, there is not a // guarantee that the restricted error info does belong to the async error code. In order to // reduce the risk that we associate incorrect information with the exception object, we need // to apply a heuristic where we attempt to match the current exception's HRESULT with the // HRESULT the IRestrictedErrorInfo belongs to. If it is a match we will assume association // for the IAsyncInfo case. if (e.HResult == restrictedErrorInfoHResult) { string errorReference; restrictedErrorInfo.GetReference(out errorReference); e.AddExceptionDataForRestrictedErrorInfo(restrictedDescription, errorReference, capabilitySid, restrictedErrorInfo); } } } catch { // If we can't get the restricted error info, then proceed as if it isn't associated with this // error. } } return(e); }
private static void RoReportUnhandledError(IRestrictedErrorInfo error) { if (!WindowsRuntimeMarshal.s_haveBlueErrorApis) { return; } try { UnsafeNativeMethods.RoReportUnhandledError(error); } catch (EntryPointNotFoundException ex) { WindowsRuntimeMarshal.s_haveBlueErrorApis = false; } }
internal static bool ReportUnhandledError(Exception e) { if (!AppDomain.IsAppXModel() || !WindowsRuntimeMarshal.s_haveBlueErrorApis || e == null) { return(false); } IntPtr pUnk = IntPtr.Zero; IntPtr ppv = IntPtr.Zero; try { pUnk = Marshal.GetIUnknownForObject((object)e); if (pUnk != IntPtr.Zero) { Marshal.QueryInterface(pUnk, ref WindowsRuntimeMarshal.s_iidIErrorInfo, out ppv); if (ppv != IntPtr.Zero) { if (WindowsRuntimeMarshal.RoOriginateLanguageException(Marshal.GetHRForException_WinRT(e), e.Message, ppv)) { IRestrictedErrorInfo restrictedErrorInfo = UnsafeNativeMethods.GetRestrictedErrorInfo(); if (restrictedErrorInfo != null) { WindowsRuntimeMarshal.RoReportUnhandledError(restrictedErrorInfo); return(true); } } } } } finally { if (ppv != IntPtr.Zero) { Marshal.Release(ppv); } if (pUnk != IntPtr.Zero) { Marshal.Release(pUnk); } } return(false); }
public static extern void RoReportUnhandledError(IRestrictedErrorInfo error);
internal static extern void RoReportUnhandledError(IRestrictedErrorInfo error);
public static void RoReportUnhandledError(IRestrictedErrorInfo error) { throw new NotImplementedException(); }