diff --git a/src/CacheManager.Core/BaseCacheManager.cs b/src/CacheManager.Core/BaseCacheManager.cs
index 353f11bc..ff48a6ff 100644
--- a/src/CacheManager.Core/BaseCacheManager.cs
+++ b/src/CacheManager.Core/BaseCacheManager.cs
@@ -5,6 +5,7 @@
using System.Linq;
using CacheManager.Core.Internal;
using CacheManager.Core.Logging;
+using CacheManager.Core.Utility;
using static CacheManager.Core.Utility.Guard;
namespace CacheManager.Core
@@ -127,7 +128,7 @@ private BaseCacheManager(string name, ICacheManagerConfiguration configuration)
catch (Exception ex)
{
Logger.LogError(ex, "Error occurred while creating the cache manager.");
- throw ex.InnerException ?? ex;
+ Throw.Rethrow(ex.InnerException ?? ex);
}
}
diff --git a/src/CacheManager.Core/Utility/Throw.cs b/src/CacheManager.Core/Utility/Throw.cs
new file mode 100644
index 00000000..b6106ed3
--- /dev/null
+++ b/src/CacheManager.Core/Utility/Throw.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Runtime.ExceptionServices;
+
+namespace CacheManager.Core.Utility
+{
+ ///
+ /// related helper.
+ ///
+ internal static class Throw
+ {
+ ///
+ /// Rethrows the supplied exception without losing its stack trace.
+ /// Prefer throw;
where possible, this method is useful for rethrowing
+ ///
+ /// which cannot be done with the throw;
semantics.
+ ///
+ /// The exception.
+ public static void Rethrow(
+ this Exception exception)
+ {
+ ExceptionDispatchInfo.Capture(exception).Throw();
+ }
+ }
+}