I have an acceptance runner program here that looks something like this:
public Result Run(CommandParser parser)
{
var result = new Result();
var watch = new Stopwatch();
watch.Start();
try
{
_testConsole.Start();
parser.ForEachInput(input =>
{
_testConsole.StandardInput.WriteLine(input);
return _testConsole.TotalProcessorTime.TotalSeconds < parser.TimeLimit;
});
if (TimeLimitExceeded(parser.TimeLimit))
{
watch.Stop();
_testConsole.Kill();
ReportThatTestTimedOut(result);
}
else
{
result.Status = GetProgramOutput() == parser.Expected ? ResultStatus.Passed : ResultStatus.Failed;
watch.Stop();
}
}
catch (Exception)
{
result.Status = ResultStatus.Exception;
}
result.Elapsed = watch.Elapsed;
return result;
}
the _testConsole is an Process adapter that wraps a regular .net process into something more workable. I do however have a hard time to catch any exceptions from the started process (i.e. the catch statement is pointless here) I'm using something like:
_process = new Process
{
StartInfo =
{
FileName = pathToProcess,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
Arguments = arguments
}
};
to set up the process. Any ideas?
Exception handling is used to handle the exceptions. We can use try catch block to protect the code. Catch block is used to catch all types of exception. The keyword “catch” is used to catch exceptions.
C doesn't support exception handling. To throw an exception in C, you need to use something platform specific such as Win32's structured exception handling -- but to give any help with that, we'll need to know the platform you care about. ...and don't use Win32 structured exception handling.
As such, C programming does not provide direct support for error handling but being a system programming language, it provides you access at lower level in the form of return values. Most of the C or even Unix function calls return -1 or NULL in case of any error and set an error code errno.
Exceptions don't flow from one process to another. The best you could do would be to monitor the exit code of the process - conventionally, an exit code of 0 represents success, and any other exit code represents an error.
Whether that's the case for the processes you're launching is a different matter, of course.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With