【发布时间】:2014-04-16 16:49:27
【问题描述】:
当使用这样的代码时(我没有权限访问 excel.exe,这是故意的):
ProcessStartInfo psi = new ProcessStartInfo("EXCEL.exe");
psi.UseShellExecute = true;
psi.ErrorDialog = true;
Process.Start(psi);
我收到了不错的 Windows 错误对话框,其中包含有关缺少权限的适当消息。这 100% 没问题,但只有当我不想记录此错误时。
假设我想使用如下代码记录它:
try
{
ProcessStartInfo psi = new ProcessStartInfo("EXCEL.exe");
psi.UseShellExecute = true;
psi.ErrorDialog = true;
Process.Start(psi);
}
catch(Win32Exception ex)
{
LogError(ex.Message) //FAIL! "The operation was canceled by the user" instead of "Access denied"
}
似乎原始异常丢失了,无论我没有权限或没有安装 excel,我总是得到相同的异常代码(消息)。
还有其他方法可以做到这一点吗?
【问题讨论】:
标签: c# .net processstartinfo