Skip to content
This repository has been archived by the owner on Jul 5, 2020. It is now read-only.

Allow users to ignore specific UnobservedTaskExceptions #1026

Closed
i3arnon opened this issue Oct 2, 2018 · 2 comments · Fixed by #1024
Closed

Allow users to ignore specific UnobservedTaskExceptions #1026

i3arnon opened this issue Oct 2, 2018 · 2 comments · Fixed by #1024

Comments

@i3arnon
Copy link
Contributor

i3arnon commented Oct 2, 2018

Sometimes you encounter UnobservedTaskExceptions that are outside of your control (e.g. in third-party libraries or in the framework itself).
Currently you can either have them mixed in with the fixable UnobservedTaskExceptions which lowers signal-to-noise ratio, or you must remove the entire UnobservedExceptionTelemetryModule.

It would be useful to have some way to ignore specific UnobservedTaskExceptions without throwing the baby with the bathwater.

@SergeyKanzhelev
Copy link
Contributor

Can you please also provide a code example on how you propose to ignore some of them.

@i3arnon
Copy link
Contributor Author

i3arnon commented Oct 3, 2018

You can ignore them by subscribing to TaskScheduler.UnobservedTaskException and marking them as observed.

For example this ignores all ObjectDisposedException and exceptions coming from UdpClient.EndReceive:

void HandleUnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs eventArgs)
{
    var exception = eventArgs.Exception.InnerException;
    if (exception is ObjectDisposedException ||
        exception?.TargetSite == typeof(UdpClient).GetMethod(nameof(UdpClient.EndReceive)))
    {
        eventArgs.SetObserved();
    }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants