dotnet / dotnet/command-line-api
`UseExceptionHandler` exit code is not honored when a custom delegate is provided
Open
bug
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 428
- PR merge metrics
- No merged PRs in 30d
Description
When both a custom `errorExitCode` value **_and_** a custom handler delegate are passed to `UseExceptionHandler`, and an exception is thrown by the handler, then the custom exit code is not honored.
```csharp
var rootCmd = new RootCommand();
rootCmd.SetHandler(_ => throw new Exception());
var parser = new CommandLineBuilder(rootCmd)
.UseExceptionHandler(
(_, _) => { },
errorExitCode: 42)
.Build();
var exitCode = parser.Invoke("");
exitCode.Should().Be(42);
// ACTUAL: 0
```
See: https://github.com/dotnet/command-line-api/issues/796#issuecomment-1273848670
Contributor guide
Assessment
This issue has not been assessed yet.