Chr*_*fer 7 c# exception .net-4.0
我刚开始使用 C# 和 .NET,但我想尝试好好发挥并重用系统组件。
在我维护的代码中,有几个我们运行外部工具和应用程序的实例,如下所示:
using (var Setup = Process.Start(SetupInfo) )
{
Setup.WaitForExit(SetupTimeout);
if (!Setup.HasExited )
throw new TimeoutException(
"Setup did not complete within the expected time");
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试为那些具有明确定义的退出代码的外部工具添加退出代码的验证,即“using”块内的类似内容:
switch ( Setup.ExitCode )
{
case 0:
break;
case 1:
throw new SetupFailedException("Setup execution failed");
case 2:
throw new SetupFileNotFound("Setup did not find required files");
default:
throw new ExternalErrorException("Setup failed for some other reason");
}
Run Code Online (Sandbox Code Playgroud)
...其中前两个将派生自通用的“ExternalErrorException”。但是,是否有一些现有的通用异常我可以重复使用,即表明外部进程未能按预期运行,而不是发明我自己的异常?