Unhandled exceptions info not quite correct

Open Beginner friendly
#27,267 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
62/100
Issue type
Documentation
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp
Domain
documentation

Research direction

Review docs/standard/threading/the-managed-thread-pool.md at the exceptions-in-thread-pool-threads section, then compare it with the linked exceptions-in-managed-threads page. Use the provided .NET 6 example to verify the distinction between task exceptions and async void exceptions. Done means the documentation accurately describes which unhandled exceptions terminate the process.

Written by the indexing model from the issue text.

Description

:watch: Not Triaged dotnet-fundamentals/svc

File: the-managed-thread-pool.md
https://docs.microsoft.com/en-us/dotnet/standard/threading/the-managed-thread-pool#exceptions-in-thread-pool-threads

Unhandled exceptions in thread pool threads terminate the process. There are three exceptions to this rule:

A System.Threading.ThreadAbortException is thrown in a thread pool thread because Thread.Abort was called.
A System.AppDomainUnloadedException is thrown in a thread pool thread because the application domain is being unloaded.
The common language runtime or a host process terminates the thread.
For more information, see Exceptions in Managed Threads.

These three exceptions to the rule come from a linked page but misses a key fourth exception to the rule. In the linked document it also states:

If any of these exceptions are unhandled in threads created by the common language runtime, the exception terminates the thread, but the common language runtime does not allow the exception to proceed further.

This second quote (also not quite correct) points to the fact that unhandled exceptions within Tasks running on the thread pool do NOT cause the process to terminate...unless they are async void. For example this .Net 6 console app:

// See https://aka.ms/new-console-template for more information
ThrowTaskExceptionAsync(); //this will NOT cause the application to crash even though the exception is unobserved
ThrowVoidExceptionAsync(); //this WILL cause the application to crash
Console.WriteLine("App still running, hit enter to continue...");
Console.ReadLine();

async void ThrowVoidExceptionAsync()
{
    await Task.Delay(1000).ConfigureAwait(false);
    throw new Exception();
}

async Task ThrowTaskExceptionAsync()
{
    await Task.Delay(1000).ConfigureAwait(false);
    throw new Exception();
}

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Dominant language
No language data
Stars
4.8k
Forks
6.1k
Avg merge
15h 30m
Merged PRs (30d)
374

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/docs

All issues in dotnet/docs

Similar issues

More Documentation issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.