-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathExceptionUtils.cs
More file actions
28 lines (25 loc) · 878 Bytes
/
ExceptionUtils.cs
File metadata and controls
28 lines (25 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Runtime.InteropServices;
namespace LibgenDesktop.Models.Utils
{
internal static class ExceptionUtils
{
public static int GetHRForException(Exception exception)
{
if (exception == null) throw new ArgumentNullException();
//on first call there is possible pollution of thread IErrorInfo with sensitive data
int hr = Marshal.GetHRForException(exception);
//therefore call with empty ex. obj. to cleanup IErrorInfo
Marshal.GetHRForException(new Exception());
return hr;
}
public static Exception GetInnermostException(this Exception exception)
{
while (exception.InnerException != null)
{
exception = exception.InnerException;
}
return exception;
}
}
}