Browse Source

Use ExceptionDispatchInfo

gnattu 7 months ago
parent
commit
bb30d26ffb
1 changed files with 5 additions and 7 deletions
  1. 5 7
      MediaBrowser.Providers/Manager/ProviderManager.cs

+ 5 - 7
MediaBrowser.Providers/Manager/ProviderManager.cs

@@ -7,6 +7,7 @@ using System.Linq;
 using System.Net;
 using System.Net;
 using System.Net.Http;
 using System.Net.Http;
 using System.Net.Mime;
 using System.Net.Mime;
+using System.Runtime.ExceptionServices;
 using System.Threading;
 using System.Threading;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using AsyncKeyedLock;
 using AsyncKeyedLock;
@@ -258,7 +259,7 @@ namespace MediaBrowser.Providers.Manager
                 throw new ArgumentNullException(nameof(source));
                 throw new ArgumentNullException(nameof(source));
             }
             }
 
 
-            Exception? saveException = null;
+            ExceptionDispatchInfo? saveException = null;
 
 
             try
             try
             {
             {
@@ -267,7 +268,7 @@ namespace MediaBrowser.Providers.Manager
             }
             }
             catch (Exception ex)
             catch (Exception ex)
             {
             {
-                saveException = ex;
+                saveException = ExceptionDispatchInfo.Capture(ex);
                 _logger.LogError(ex, "Unable to save image {Source}", source);
                 _logger.LogError(ex, "Unable to save image {Source}", source);
             }
             }
             finally
             finally
@@ -282,14 +283,11 @@ namespace MediaBrowser.Providers.Manager
                 }
                 }
                 catch (Exception ex)
                 catch (Exception ex)
                 {
                 {
-                    saveException ??= ex;
+                    saveException ??= ExceptionDispatchInfo.Capture(ex);
                 }
                 }
             }
             }
 
 
-            if (saveException is not null)
-            {
-                throw saveException;
-            }
+            saveException?.Throw();
         }
         }
 
 
         /// <inheritdoc/>
         /// <inheritdoc/>