Skip to content

Commit

Permalink
Conditional compilation logic simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
bugsnagbot committed May 13, 2020
1 parent 064d9a8 commit 9915f93
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/Bugsnag/UnhandledException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,11 @@ class UnhandledException

private readonly object _currentClientLock = new object();
private IClient _currentClient;
#if !(NET35 || NET40)
private bool _unobservedTerminates;
#endif

private UnhandledException()
{
#if !(NET35 || NET40)
_unobservedTerminates = DetermineUnobservedTerminates();
#endif
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
Expand Down Expand Up @@ -59,7 +55,9 @@ public void ConfigureClient(IClient client, IConfiguration configuration)
/// <returns></returns>
private bool DetermineUnobservedTerminates()
{
#if NET45
#if NET35 || NET40
return true;
#elif NET45
System.Xml.Linq.XElement configFile = System.Xml.Linq.XElement.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
var configValue = configFile?.Element("runtime")?.Element("ThrowUnobservedTaskExceptions")?.Attribute("enabled")?.Value;
bool value;
Expand All @@ -77,11 +75,7 @@ private void CurrentDomain_ProcessExit(object sender, EventArgs e)

private void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
#if NET35 || NET40
HandleEvent(e.Exception as Exception, !e.Observed);
#else
HandleEvent(e.Exception as Exception, _unobservedTerminates);
#endif
HandleEvent(e.Exception as Exception, _unobservedTerminates && !e.Observed);
}

[HandleProcessCorruptedStateExceptions]
Expand Down

0 comments on commit 9915f93

Please sign in to comment.