-
Notifications
You must be signed in to change notification settings - Fork 84
Open
Description
Observed behavior
In below console app an Unobserved task exception is observed although the connect attempt is in a try/catch block.
Expected behavior
All exceptions can be handled gracefully.
Server and client version
Version 2.6.11
Host environment
No response
Steps to reproduce
using NATS.Client.Core;
TaskScheduler.UnobservedTaskException += (sender, eventArgs) =>
{
Console.WriteLine($"Unobserved task exception: {eventArgs.Exception}");
eventArgs.SetObserved();
};
var connection
= new NatsConnection(
NatsOpts.Default with { Url = "nats:/user@pass:sorry" });
await using (connection.ConfigureAwait(false))
{
try
{
await connection.ConnectAsync().ConfigureAwait(false);
Console.WriteLine("Connected to NATS server.");
}
catch (Exception ex)
{
Console.WriteLine($"Failed to connect to NATS server: {ex.Message}");
}
await Task.Delay(500).ConfigureAwait(false);
GC.Collect();
GC.WaitForPendingFinalizers();
Console.WriteLine("Exiting application.");
}mtmk
Metadata
Metadata
Assignees
Labels
No labels