try
{
//代码
}
catch(Exception e)
{
var w32ex = e as Win32Exception;
if (w32ex == null)
{
w32ex = e.InnerException as Win32Exception;
}
if (w32ex != null)
{
//根据code来判别错误
int code = w32ex.ErrorCode;
}
}