runtime: [API Proposal]: Add a property or method that can be used to check if there is an error in the process
Background and motivation
Add a property or method that can be used to check if there is an error in the process https://github.com/Mr0N/ExampleProcessStart/blob/master/ExampleProcessStart/Program.cs
API Proposal
static class Info
{
public static void CheckException(this Process process)
{
if (string.IsNullOrEmpty(process.StandardError.ReadToEnd()))
throw new Exception();
}
}
API Usage
var info = new ProcessStartInfo()
{
FileName = "cmd.exe",
RedirectStandardError = true,
RedirectStandardOutput = true,
RedirectStandardInput = true
};
var process = Process.Start(info);
process.CheckException();
string text = process.StandardOutput.ReadToEnd();
Alternative Designs
No response
Risks
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 38 (10 by maintainers)
Feel free to offer a PR to clarify documentation if you think it would be helpful. I will close this for the reasons described by others above.
The definition of “error” looks extremely unclear.
When is it involved? A business logic failure, or the process fails to load some necessary library? What about error level? Some errors are recoverable, some are fatal, and some are simply ignorable - some programs reports “nothing to do” as error. Where to achieve the state of the process? Stderr is very often used for informational logging. Some programs use return code to represent meaningful information. GUI program may not use neither of them.