I'm new to using C# and .NET, but I want to try to play nice and re-use system components.
In the code I'm maintaining, there are several instances where we run external tools and applications, which looks something like this:
using (var Setup = Process.Start(SetupInfo) )
{
Setup.WaitForExit(SetupTimeout);
if (!Setup.HasExited )
throw new TimeoutException(
"Setup did not complete within the expected time");
}
I'm trying to add validation of the exit codes as well for those external tools that have well-defined exit codes, i.e. something like this inside the 'using' block:
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");
}
...where the first two would derive from the generic 'ExternalErrorException'. But is there some existing generic exception I could re-use for this, i.e. to signal that an external process has failed to run as expected, rather than invent my own?