commandlineparser / commandlineparser/commandline

WithParsed(async swallows exceptions

Offen
#773 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
C#
Sterne
4.8k
Forks
478
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

### Some examples of the use of WithParsed / WithParsedAsync with expected behavior
```
internal static class Program
{
private static void Main(string[] args)
{
Parser.Default.ParseArguments(args).WithParsed(_ => throw new Exception());
```
=> Unhandled exception. System.Exception: Exception of type 'System.Exception' was thrown.
As Expected.

```
internal static class Program
{
private static async Task Main(string[] args)
{
await Parser.Default.ParseArguments(args).WithParsedAsync(_ => throw new Exception());
```
=> Unhandled exception. System.Exception: Exception of type 'System.Exception' was thrown.
As Expected.

```
internal static class Program
{
private static async Task Main(string[] args)
{
await Parser.Default.ParseArguments(args).WithParsedAsync(async _ =>
{
await Task.CompletedTask; //just for demonstration
throw new Exception();
});
```
=> Unhandled exception. System.Exception: Exception of type 'System.Exception' was thrown.
As Expected.

### When using WithParsed with an async expresion in a synchrone context, it swallows the exception

```
internal static class Program
{
private static void Main(string[] args)
{
Parser.Default.ParseArguments(args).WithParsed(async _ =>
{
await Task.CompletedTask; //just for demonstration
throw new Exception();
});
```
=> Process finished with exit code 0.
Should also notify about Unhandled exception.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.