Questions tagged [unobserved-exception]

In the Task Parallel Library (TPL), an unobserved exception is one which is thrown by the finalizer thread when a Task exception occurs but is not actively observed.

In the Task Parallel Library (TPL), an unobserved exception is one which is thrown by the finalizer thread when a Task exception occurs but is not actively observed.

References

18 questions
42
votes
3 answers

How to handle all unhandled exceptions when using Task Parallel Library?

I'm using the TPL (Task Parallel Library) in .NET 4.0. I want to centralize the handling logic of all unhandled exceptions by using the Thread.GetDomain().UnhandledException event. However, in my application, the event is never fired for threads…
14
votes
1 answer

OperationCanceledException from System.Web.Http.HostAuthenticationFilter

We were recently checking our error logs and saw lots of "The operation was canceled" exceptions. We were not able to reproduce them, looks like an aborted request, but they all come from OWIN HostAuthenticationFilter. Here is the stack…
9
votes
2 answers

Test for UnObserved Exceptions

I have a C# Extension method that can be used with tasks to make sure any exceptions thrown are at the very minimum observed, so as to not crash the hosting process. In .NET4.5, the behavior has changed slightly so this won't happen, however the…
Pete Garafano
  • 4,863
  • 1
  • 23
  • 40
7
votes
3 answers

The operation was canceled at TaskScheduler.UnobservedTaskException in WebAPI

Recently I have added error logging for every UnobservedTaskException at my backend API app. The reason is that some API call executes additional tasks which are finished AFTER I return the result, that is why I couldn't track errors there on…
Mando
  • 11,414
  • 17
  • 86
  • 167
6
votes
1 answer

Task Continuation (OnlyOnFaulted) still gets unobserved exception

I have a task with a continuation to handle errors: var uiScheduler = TaskScheduler.FromCurrentSynchronizationContext(); var loadTask = Task>.Factory.StartNew(() => { throw new Exception("derp"); }); var…
4
votes
2 answers

Using the UnobservedTaskException handler in dotnetcoreapp2.0

The following code, when run in a netcoreapp2.0 application, doesn't seem to end up throwing the UnobservedTaskException using System; using System.Threading; using System.Threading.Tasks; namespace ConsoleApp3 { class Program { …
bboyle1234
  • 4,859
  • 2
  • 24
  • 29
4
votes
1 answer

UnobservedTaskException is not killing the process

I am trying to understand the UnobservedTaskException issue in .NET 4.0 so I wrote the folloging code TaskScheduler.UnobservedTaskException += (sender, eventArgs) => Console.WriteLine("unobserved"); Task.Factory.StartNew(() => { throw new…
3
votes
4 answers

Handling exception from non-awaited Task

Let's assume I have a console application with Main method, something like this: public static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { Console.WriteLine("App Unobserved"); …
3
votes
0 answers

Why the logic of UnobservedTaskException was changed in .net 4.5?

As we know in .net 4.5 UnobservedTaskException does not crash an app. To make it easier for developers to write asynchronous code based on tasks, the .NET Framework 4.5 changes the default exception behavior for unobserved exceptions. Although…
Serg046
  • 1,043
  • 1
  • 13
  • 42
3
votes
2 answers

Does ContinueWhenAll observe the exceptions and hence prevent an UnobservedTaskException?

Suppose I have an array of tasks say taskArray and I create a task continuation using ContinueWhenAll and one or more of the tasks in taskArray throw some exception. My question is, is there any scenario where this may lead to an…
Anupam
  • 870
  • 4
  • 9
  • 19
3
votes
4 answers

Debugging a failing, unobserved TPL task

I am attempting to debug an intermittent issue I am observing via a failing integration test, but seem to be stuck between a rock and a hard place. Something, somewhere, is creating a System.Threading.Tasks.Task that is subsequently failing and…
Kent Boogaart
  • 175,602
  • 35
  • 392
  • 393
2
votes
1 answer

Can "ThrowIfCancellationRequested" not be caught by TaskScheduler_UnobservedTaskException?

I have a very very strange problem, and here's my codes now: namespace TaskParallelTest { using System.Threading; using System.Threading.Tasks; using System; using System.IO; public class Program { static Program() …
xqMogvKW
  • 628
  • 7
  • 17
2
votes
3 answers

Catch-all Exception Handler for non-UI Threads in WPF

Specifically, I'm using WPF with MVVM. I have a MainWindow, which is a WPF Window where all of the action happens. It uses a corresponding View Model class for its properties, commands, etc. I have set up main UI thread and non-UI thread exception…
Sandra
  • 608
  • 2
  • 11
  • 23
2
votes
1 answer

Unhandled exceptions when using TPL while OnlyOnFaulted is presented

This is a sample code from a "C# 5.0 in a Nutshell" TaskCreationOptions atp = TaskCreationOptions.AttachedToParent; Task.Factory.StartNew (() => { Task.Factory.StartNew (() => { throw null; }, atp); Task.Factory.StartNew (() => { throw null;…
aush
  • 2,108
  • 1
  • 14
  • 24
1
vote
1 answer

Handling unobserved Task exceptions

I know that I can handle the UnobservedTaskException to prevent any unobserved exceptions from terminating my application when the finalizer runs on the object. However, I'm not sure where or when I should set up the handler for this event. The XML…
1
2