using System;
namespace NAudio
{
///
/// Summary description for MmException.
///
public class MmException : Exception
{
private MmResult result;
private string function;
///
/// Creates a new MmException
///
/// The result returned by the Windows API call
/// The name of the Windows API that failed
public MmException(MmResult result, string function)
: base(MmException.ErrorMessage(result, function))
{
this.result = result;
this.function = function;
}
private static string ErrorMessage(MmResult result, string function)
{
return String.Format("{0} calling {1}", result, function);
}
///
/// Helper function to automatically raise an exception on failure
///
/// The result of the API call
/// The API function name
public static void Try(MmResult result, string function)
{
if (result != MmResult.NoError)
throw new MmException(result, function);
}
///
/// Returns the Windows API result
///
public MmResult Result
{
get
{
return result;
}
}
}
}