本文整理汇总了C#中Exception.SetErrorCode方法的典型用法代码示例。如果您正苦于以下问题:C# Exception.SetErrorCode方法的具体用法?C# Exception.SetErrorCode怎么用?C# Exception.SetErrorCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Exception
的用法示例。
在下文中一共展示了Exception.SetErrorCode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WaitForMultipleObjects
internal static unsafe int WaitForMultipleObjects(IntPtr* pHandles, int numHandles, bool waitAll, int millisecondsTimeout)
{
Debug.Assert(millisecondsTimeout >= -1);
//
// In the CLR, we use CoWaitForMultipleHandles to pump messages while waiting in an STA. In that case, we cannot use WAIT_ALL.
// That's because the wait would only be satisfied if a message arrives while the handles are signalled.
//
if (waitAll)
{
if (numHandles == 1)
waitAll = false;
else if (GetCurrentApartmentType() == ApartmentType.STA)
throw new NotSupportedException(SR.NotSupported_WaitAllSTAThread);
}
int result;
if (ReentrantWaitsEnabled)
{
Debug.Assert(!waitAll);
result = RuntimeImports.RhCompatibleReentrantWaitAny(false, millisecondsTimeout, numHandles, pHandles);
}
else
{
result = (int)Interop.mincore.WaitForMultipleObjectsEx((uint)numHandles, (IntPtr)pHandles, waitAll, (uint)millisecondsTimeout, false);
}
if (result == WAIT_FAILED)
{
int error = (int)Interop.mincore.GetLastError();
switch (error)
{
case Interop.mincore.Errors.ERROR_INVALID_PARAMETER:
throw new ArgumentException();
case Interop.mincore.Errors.ERROR_ACCESS_DENIED:
throw new UnauthorizedAccessException();
case Interop.mincore.Errors.ERROR_NOT_ENOUGH_MEMORY:
throw new OutOfMemoryException();
default:
Exception ex = new Exception();
ex.SetErrorCode(error);
throw ex;
}
}
return result;
}
示例2: EnsureHasMarshalProxy
private static void EnsureHasMarshalProxy()
{
if (s_winRtMarshalProxy != null)
return;
try
{
IMarshal proxy;
Int32 hr = Interop.mincore.RoGetBufferMarshaler(out proxy);
s_winRtMarshalProxy = proxy;
if (hr != HResults.S_OK)
{
Exception ex = new Exception(String.Format("{0} ({1}!RoGetBufferMarshaler)", SR.WinRtCOM_Error, WinTypesDLL));
ex.SetErrorCode(hr);
throw ex;
}
if (proxy == null)
throw new NullReferenceException(String.Format("{0} ({1}!RoGetBufferMarshaler)", SR.WinRtCOM_Error, WinTypesDLL));
}
catch (DllNotFoundException ex)
{
throw new NotImplementedException(SR.Format(SR.NotImplemented_NativeRoutineNotFound,
String.Format("{0}!RoGetBufferMarshaler", WinTypesDLL)),
ex);
}
}