Skip to content
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

Add Rethrow() method and use in BaseCacheManager #307

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/CacheManager.Core/BaseCacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/CacheManager.Core/Utility/Throw.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Runtime.ExceptionServices;

namespace CacheManager.Core.Utility
{
/// <summary>
/// <see cref="Exception"/> related helper.
/// </summary>
internal static class Throw
{
/// <summary>
/// Rethrows the supplied exception without losing its stack trace.
/// Prefer <code>throw;</code> where possible, this method is useful for rethrowing
/// <see cref="Exception.InnerException" />
/// which cannot be done with the <code>throw;</code> semantics.
/// </summary>
/// <param name="exception">The exception.</param>
public static void Rethrow(
this Exception exception)
{
ExceptionDispatchInfo.Capture(exception).Throw();
}
}
}