forked from naudio/NAudio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMmException.cs
50 lines (43 loc) · 1.43 KB
/
MmException.cs
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
namespace NAudio
{
/// <summary>
/// Summary description for MmException.
/// </summary>
public class MmException : Exception
{
/// <summary>
/// Creates a new MmException
/// </summary>
/// <param name="result">The result returned by the Windows API call</param>
/// <param name="function">The name of the Windows API that failed</param>
public MmException(MmResult result, string function)
: base(ErrorMessage(result, function))
{
Result = result;
Function = function;
}
private static string ErrorMessage(MmResult result, string function)
{
return $"{result} calling {function}";
}
/// <summary>
/// Helper function to automatically raise an exception on failure
/// </summary>
/// <param name="result">The result of the API call</param>
/// <param name="function">The API function name</param>
public static void Try(MmResult result, string function)
{
if (result != MmResult.NoError)
throw new MmException(result, function);
}
/// <summary>
/// Returns the Windows API result
/// </summary>
public MmResult Result { get; }
/// <summary>
/// The function being called
/// </summary>
public string Function { get; }
}
}