Skip to content

Commit

Permalink
Defend against losing the first exception's message when Exception.To…
Browse files Browse the repository at this point in the history
…String() throws
  • Loading branch information
AArnott committed Sep 23, 2021
1 parent 496c359 commit 5e7a00e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/nbgv/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,23 @@ private static Parser BuildCommandLine()
}
}
}, (MiddlewareOrder)(-3000)) // MiddlewareOrderInternal.ExceptionHandler so [parse] directive is accurate.
.UseExceptionHandler((ex, context) => PrintException(ex, context))
.Build();
}

private static void PrintException(Exception ex, InvocationContext context)
{
try
{
Console.Error.WriteLine("Unhandled exception: {0}", ex);
}
catch (Exception ex2)
{
Console.Error.WriteLine("Unhandled exception: {0}", ex.Message);
Console.Error.WriteLine("Unhandled exception while trying to print string version of the above exception: {0}", ex2);
}
}

private static int MainInner(string[] args)
{
try
Expand Down

0 comments on commit 5e7a00e

Please sign in to comment.