-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.net core 2.1 AppDomain.CurrentDomain.UnhandledException #11546
Comments
From @MarcoRossignoli on November 26, 2018 10:6 Seems not supported /cc @jkotas |
This is not supported in .NET Core (and it did not work reliably in .NET Framework for a while either). Unhandled exception will cause the program to be terminated. Why do you need unhandled exceptions to be ignored? |
@jkotas Finally, thank you. |
Back during .NET Framework 1.x, we have found that silently ignoring unhandled exceptions just leads to much worse reliability problems later as explained in https://docs.microsoft.com/en-us/dotnet/standard/threading/exceptions-in-managed-threads. We do not have plans to encourage or support silently ignoring unhandled exceptions. cc @janvorli |
OK, thank you. |
Is there anything actionable here or this issue can be closed? |
But what is the difference between adding try { } catch (Exception e) when (HandleException(e)) { // eat } "We do not have plans to encourage or support silently ignoring unhandled exceptions" |
I've encountered this problem while working on the integration of Any suggestions? |
@nxrighthere I have a naïve question - do the dynamically loaded assemblies have some well defined interface so that you could catch all exceptions on it? |
Nope, but I can implement this. A perfect solution for me would be to handle this globally and transparently for the end-user without involving an additional code into dynamic assemblies. |
I think that you can make it work without end user being involved probably in majority of the cases, however if the end user code used e.g. threads, strong GC handles, RegisteredWaitHandles or if it registered an event handler to some event that lives outside of their code (e.g. System.Diagnostics.Process.Exited) , it would need to cooperate on the shutdown by registering AssemblyLoadContext.OnUnload handler and shutting the threads, closing the strong handles, unregistering events etc. |
Please see https://docs.microsoft.com/en-us/dotnet/standard/assembly/unloadability for all the details. |
@janvorli Yes, but how to prevent termination of the process that embeds |
My point was that if you can catch all the exception at the interface, there should not be any unhandled exceptions (other than access violations). |
Interesting, the process is still get terminated even if the code is wrapped with try/catch block: try {
throw new Exception("Test exception");
}
catch (Exception exception) {
return;
}
|
Are you saying that it behaves like this even in the simple block that looks exactly like what you've pasted above or is the throw somewhere in the code running inside of the unloadable context and the catch outside of it? |
Yes, it behaves like that exactly with this code. A dynamic assembly with a static function is loaded at runtime using |
So the throw / catch is inside the loaded assembly, right? Does the problem happen also when running without debugging (when running from command line or when running from the VS using "Start without debugging")? |
Yes. Exceptions in the parent assembly which was loaded using
Nope, it works as intended just like in the parent assembly of |
Ok, then it is a problem with debugger / debugger support code. It may be the same as #2317. |
Yes, I have the exact same problem. Thank you for pointing me to this issue. |
Closing as dup of #2317 |
From @zhaojie on November 26, 2018 6:20
.net core 2.1
To avoid program crash, I use AppDomain.CurrentDomain.UnhandledException to catch the unhandledexception,but the program still crashes and exits
Where to set this property of UnhandledExceptionEventArgs.IsTerminating ?
.net, can set this legacyUnhandledExceptionPolicy
<runtime> <legacyUnhandledExceptionPolicy enabled="true" /> </runtime>
but in .net core, hot to do?
Copied from original issue: dotnet/corefx#33689
The text was updated successfully, but these errors were encountered: