dotnet / dotnet/command-line-api
How do we implement exception handling around Command.Invoke?
Open
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 428
- PR merge metrics
- No merged PRs in 30d
Description
I have created a simple .NET Core console application with this line to execute the `Command`
```
try
{
rootCommand.Invoke(args)
}
catch
{
Console.Error.Write("Something bad happened");
}
```
But when the command handler associated to the command throws an exception, the catch block isn't executed. Instead, the Invoke method returns a non-zero integer.
So, what's the correct method to handle exceptions around `Invoke`/`InvokeAsync`?
Contributor guide
Assessment
This issue has not been assessed yet.