Skip to content

Unhandled exception handler. - #109806

Merged
VSadov merged 16 commits into
dotnet:mainfrom
VSadov:unh
Nov 26, 2024
Merged

Unhandled exception handler.#109806
VSadov merged 16 commits into
dotnet:mainfrom
VSadov:unh

Conversation

@VSadov

@VSadovVSadov commented Nov 14, 2024

Copy link
Copy Markdown
Member

The managed part of #101560
It implements the public static void SetUnhandledExceptionHandler(UnhandledExceptionHandler handler); API

This covers CoreCLR and NativeAOT.
(Mono will need to be addressed separately)

@ghostghost added needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners new-api-needs-documentation labels Nov 14, 2024
@ghost

Copy link
Copy Markdown

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

1 similar comment
@ghost

Copy link
Copy Markdown

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@VSadovVSadov added runtime-coreclr specific to the CoreCLR runtime area-NativeAOT-coreclr area-ExceptionHandling-coreclr only use for closed issues area-VM-coreclr and removed new-api-needs-documentation needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners runtime-coreclr specific to the CoreCLR runtime labels Nov 14, 2024
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

@VSadov

VSadov commented Nov 15, 2024

Copy link
Copy Markdown
MemberAuthor

Build browser-wasm linux Release LibraryTests is timing out at build stage. It is probably not related to the changes in this PR

@VSadov
VSadov marked this pull request as ready for review November 15, 2024 01:35
@VSadov
VSadov requested review from janvorli and jkotas and removed request for MichalStrehovskyNovember 15, 2024 01:35
@VSadov

Copy link
Copy Markdown
MemberAuthor

I think this is ready for review.

@VSadov

VSadov commented Nov 15, 2024

Copy link
Copy Markdown
MemberAuthor

(Mono will need to be addressed separately)

That is because I am far less familiar with where the relevant pieces are in Mono, so I'd like to get CoreCLR/NativeAOT and tests settled.
I may need help with Mono.

Comment threadsrc/coreclr/System.Private.CoreLib/src/System/GC.CoreCLR.cs Outdated
Comment threadsrc/libraries/System.Runtime/ref/System.Runtime.cs Outdated
Comment threadsrc/tests/baseservices/exceptions/unhandledHandler/HandlerRefuses.cs Outdated
Comment threadsrc/tests/baseservices/exceptions/unhandledHandler/HandlerThrows.cs Outdated
#include <pthread.h>
#endif // _WIN32

// Work around typedef redefinition: platformdefines.h defines error_t

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if the platformdefines.h should be fixed instead to not to define the error_t and include the errno.h instead.

public class PInvokeRevPInvokeUnhandled
{
[DllImport("ForeignThreadRevPInvokeUnhandled")]
public static extern void InvokeCallback(MyCallback callback);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot see this being used in this test

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied the file between two tests. One uses InvokeCallback another uses InvokeCallbackOnNewThread. I can remove redundant ones.

@jkotasjkotas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you!

@VSadov

Copy link
Copy Markdown
MemberAuthor

The failure in x86 tests is #110127

@VSadov

Copy link
Copy Markdown
MemberAuthor

/ba-g #110127

@VSadov
VSadov merged commit 17cb826 into dotnet:mainNov 26, 2024
@VSadov
VSadov deleted the unh branch November 26, 2024 00:03

namespace System.Runtime.ExceptionServices
{
public delegate bool UnhandledExceptionHandler(System.Exception exception);

@teo-tsirpanisteo-tsirpanisNov 26, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VSadov the approved API shape used Func<Exception, bool> instead of a custom delegate.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VSadov the approved API shape used Func<Exception, bool> instead of a custom delegate.

@VSadov do you have plans to address this? We cannot check in new unapproved public APIs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened #110254.

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you have plans to address this? We cannot check in new unapproved public APIs.

Yes. It was an oversight.
The approved shape was the same as in proposal except for this part. I missed that there was a diff from the proposal.

mikelle-rogers pushed a commit to mikelle-rogers/runtime that referenced this pull request Dec 10, 2024
* unhandled exceptions in Finalizers (Core and AOT)
* catch in threadpool
* handle in threads
* trivial tests
* HandlerThrows
* HandlerRefuses
* NoEffectInMainThread
* Rev PInvoke tests
* make all pri-0 and disable on mono
* use ?.
* whitespaces
* rename unhandledHandler-->UnhandledExceptionHandler
* PR feedback
* define error_t as int
* ref/System.Runtime formatting
* Update src/tests/baseservices/exceptions/UnhandledExceptionHandler/UnhandledTrivial.cs
---------
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
baronfel added a commit to dotnet/msbuild that referenced this pull request Dec 19, 2024
The latest daily build of the .NET 10 SDK fails to build the msbuild
repo due to the following build error:
```
/repos/dotnet/src/msbuild/src/Build/BackEnd/BuildManager/BuildManager.cs(1330,41): error CS0104: 'ExceptionHandling' is an ambiguous reference between 'Microsoft.Build.Shared.ExceptionHandling' and 'System.Runtime.ExceptionServices.ExceptionHandling' [/repos/dotnet/src/msbuild/src/Build/Microsoft.Build.csproj]
/repos/dotnet/src/msbuild/src/Build/BackEnd/Components/ProjectCache/ProjectCacheService.cs(875,17): error CS0104: 'ExceptionHandling' is an ambiguous reference between 'Microsoft.Build.Shared.ExceptionHandling' and 'System.Runtime.ExceptionServices.ExceptionHandling' [/repos/dotnet/src/msbuild/src/Build/Microsoft.Build.csproj]
/repos/dotnet/src/msbuild/src/Build/BackEnd/BuildManager/BuildManager.cs(1437,57): error CS0104: 'ExceptionHandling' is an ambiguous reference between 'Microsoft.Build.Shared.ExceptionHandling' and 'System.Runtime.ExceptionServices.ExceptionHandling' [/repos/dotnet/src/msbuild/src/Build/Microsoft.Build.csproj]
/repos/dotnet/src/msbuild/src/Build/BackEnd/BuildManager/BuildManager.cs(1448,41): error CS0104: 'ExceptionHandling' is an ambiguous reference between 'Microsoft.Build.Shared.ExceptionHandling' and 'System.Runtime.ExceptionServices.ExceptionHandling' [/repos/dotnet/src/msbuild/src/Build/Microsoft.Build.csproj]
/repos/dotnet/src/msbuild/src/Build/BackEnd/BuildManager/BuildManager.cs(1584,17): error CS0104: 'ExceptionHandling' is an ambiguous reference between 'Microsoft.Build.Shared.ExceptionHandling' and 'System.Runtime.ExceptionServices.ExceptionHandling' [/repos/dotnet/src/msbuild/src/Build/Microsoft.Build.csproj]
/repos/dotnet/src/msbuild/src/Build/BackEnd/BuildManager/BuildManager.cs(1806,49): error CS0104: 'ExceptionHandling' is an ambiguous reference between 'Microsoft.Build.Shared.ExceptionHandling' and 'System.Runtime.ExceptionServices.ExceptionHandling' [/repos/dotnet/src/msbuild/src/Build/Microsoft.Build.csproj]
/repos/dotnet/src/msbuild/src/Build/BackEnd/BuildManager/BuildManager.cs(1879,21): error CS0104: 'ExceptionHandling' is an ambiguous reference between 'Microsoft.Build.Shared.ExceptionHandling' and 'System.Runtime.ExceptionServices.ExceptionHandling' [/repos/dotnet/src/msbuild/src/Build/Microsoft.Build.csproj]
/repos/dotnet/src/msbuild/src/Build/BackEnd/BuildManager/BuildManager.cs(1879,66): error CS0104: 'ExceptionHandling' is an ambiguous reference between 'Microsoft.Build.Shared.ExceptionHandling' and 'System.Runtime.ExceptionServices.ExceptionHandling' [/repos/dotnet/src/msbuild/src/Build/Microsoft.Build.csproj]
/repos/dotnet/src/msbuild/src/Build/BackEnd/BuildManager/BuildManager.cs(2483,44): error CS0104: 'ExceptionHandling' is an ambiguous reference between 'Microsoft.Build.Shared.ExceptionHandling' and 'System.Runtime.ExceptionServices.ExceptionHandling' [/repos/dotnet/src/msbuild/src/Build/Microsoft.Build.csproj]
/repos/dotnet/src/msbuild/src/Build/BackEnd/BuildManager/BuildManager.cs(2484,161): error CS0104: 'ExceptionHandling' is an ambiguous reference between 'Microsoft.Build.Shared.ExceptionHandling' and 'System.Runtime.ExceptionServices.ExceptionHandling' [/repos/dotnet/src/msbuild/src/Build/Microsoft.Build.csproj]
/repos/dotnet/src/msbuild/src/Build/BackEnd/BuildManager/BuildManager.cs(2493,169): error CS0104: 'ExceptionHandling' is an ambiguous reference between 'Microsoft.Build.Shared.ExceptionHandling' and 'System.Runtime.ExceptionServices.ExceptionHandling' [/repos/dotnet/src/msbuild/src/Build/Microsoft.Build.csproj]
/repos/dotnet/src/msbuild/src/Build/BackEnd/BuildManager/BuildManager.cs(2976,41): error CS0104: 'ExceptionHandling' is an ambiguous reference between 'Microsoft.Build.Shared.ExceptionHandling' and 'System.Runtime.ExceptionServices.ExceptionHandling' [/repos/dotnet/src/msbuild/src/Build/Microsoft.Build.csproj]
```
This is due to a conflict in a class name with a new public class from
runtime: dotnet/runtime#109806
Fixed by explicitly defining the namespace to use.
This was found as part of the work on
dotnet/sdk#45435.
@github-actionsgithub-actionsBot locked and limited conversation to collaborators Dec 29, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-ExceptionHandling-coreclronly use for closed issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@VSadov@jkotas@janvorli@teo-tsirpanis@MichalStrehovsky