diff options
author | monojenkins <jo.shields+jenkins@xamarin.com> | 2020-03-13 17:04:42 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-13 17:04:42 +0300 |
commit | d90665a422e9f8d015585b3ca381d74faa033cc4 (patch) | |
tree | 77d1f55ddfbf50ea2e93330bdb0059feab986819 /mcs/class | |
parent | 74bf77a59c28481771714684ca95ca0fbdda49a3 (diff) |
[2020-02] [corlib] Capture the ExceptionDispatchInfo when rethrowing from TaskContinuation (#19209)
* [corlib] Capture the ExceptionDispatchInfo when rethrowing from TaskContinuation
In `task.GetAwaiter().OnCompleted(action)` if `action` throws, the
`TaskContinuation.RunOrScheduleAction method will catch the exception and then
call `RuntimeAugments.ReportUnhandledException`. We must not simply throw the
exception again - in that case we will lose all the frames leading up to the
`catch` in `RunOrScheduleAction`. Instead use ExceptionDispatchInfo to
caputure the original throw.
Addresses https://github.com/mono/mono/issues/19166
* [test] Add regression test
For annoying reasons we can't run this as a simple NUnit test because the
exception is unhandled on some arbitrary threadpool worker thread, and those
don't show up within an NUnit setup.
Additionally because the unhandled exception in the root domain would normally
terminate the application, we need to run this in a new appdomain.
Co-authored-by: Aleksey Kliger <alklig@microsoft.com>
Diffstat (limited to 'mcs/class')
-rw-r--r-- | mcs/class/corlib/corert/RuntimeAugments.cs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/mcs/class/corlib/corert/RuntimeAugments.cs b/mcs/class/corlib/corert/RuntimeAugments.cs index c1dc3f3cb93..b55c5ea9a4c 100644 --- a/mcs/class/corlib/corert/RuntimeAugments.cs +++ b/mcs/class/corlib/corert/RuntimeAugments.cs @@ -1,5 +1,6 @@ using System; using System.Reflection; +using System.Runtime.ExceptionServices; namespace Internal.Runtime.Augments { partial class RuntimeAugments { @@ -7,7 +8,8 @@ namespace Internal.Runtime.Augments { public static void ReportUnhandledException (Exception exception) { - throw exception; + var edi = ExceptionDispatchInfo.Capture (exception); + edi.Throw (); } internal static ReflectionExecutionDomainCallbacks Callbacks => s_reflectionExecutionDomainCallbacks; @@ -19,4 +21,4 @@ namespace Internal.Runtime.Augments { return new MissingMetadataException (); } } -}
\ No newline at end of file +} |