t1 / TFDContents / Assets / Standard Assets / ExceptionHelper.cs @ 10
이력 | 보기 | 이력해설 | 다운로드 (1.77 KB)
1 | 3 | KTH | #if !(UNITY_WSA_10_0 && NETFX_CORE) |
---|---|---|---|
2 | using System; |
||
3 | using System.Runtime.InteropServices; |
||
4 | |||
5 | namespace Helper |
||
6 | { |
||
7 | public static class ExceptionHelper |
||
8 | { |
||
9 | private const int E_NOTIMPL = unchecked((int)0x80004001); |
||
10 | private const int E_OUTOFMEMORY = unchecked((int)0x8007000E); |
||
11 | private const int E_INVALIDARG = unchecked((int)0x80070057); |
||
12 | private const int E_POINTER = unchecked((int) 0x80004003); |
||
13 | private const int E_PENDING = unchecked((int)0x8000000A); |
||
14 | private const int E_FAIL = unchecked((int)0x80004005); |
||
15 | |||
16 | public static void CheckLastError() |
||
17 | { |
||
18 | int hr = Marshal.GetLastWin32Error(); |
||
19 | |||
20 | if ((hr == E_PENDING) || (hr == E_FAIL)) |
||
21 | { |
||
22 | // Ignore E_PENDING/E_FAIL - We use this to indicate no pending or missed frames |
||
23 | return; |
||
24 | } |
||
25 | |||
26 | if (hr < 0) |
||
27 | { |
||
28 | Exception exception = Marshal.GetExceptionForHR(hr); |
||
29 | string message = string.Format("This API has returned an exception from an HRESULT: 0x{0:X}", hr); |
||
30 | |||
31 | switch (hr) |
||
32 | { |
||
33 | case E_NOTIMPL: |
||
34 | throw new NotImplementedException(message, exception); |
||
35 | |||
36 | case E_OUTOFMEMORY: |
||
37 | throw new OutOfMemoryException(message, exception); |
||
38 | |||
39 | case E_INVALIDARG: |
||
40 | throw new ArgumentException(message, exception); |
||
41 | |||
42 | case E_POINTER: |
||
43 | throw new ArgumentNullException(message, exception); |
||
44 | |||
45 | default: |
||
46 | throw new InvalidOperationException(message, exception); |
||
47 | } |
||
48 | } |
||
49 | } |
||
50 | } |
||
51 | } |
||
52 | #endif |