Cleanup BootFailedException

This commit is contained in:
Stephan
2018-10-25 15:07:04 +02:00
parent d3a894b7a3
commit d1e377bc38
3 changed files with 47 additions and 18 deletions

View File

@@ -1,9 +1,10 @@
using System;
using System.Text;
namespace Umbraco.Core.Exceptions
{
/// <summary>
/// An exception that is thrown if the Umbraco application cannnot boot.
/// An exception that is thrown if the Umbraco application cannot boot.
/// </summary>
public class BootFailedException : Exception
{
@@ -29,5 +30,31 @@ namespace Umbraco.Core.Exceptions
public BootFailedException(string message, Exception inner)
: base(message, inner)
{ }
/// <summary>
/// Rethrows a captured <see cref="BootFailedException"/>.
/// </summary>
/// <remarks>The exception can be null, in which case a default message is used.</remarks>
public static void Rethrow(BootFailedException bootFailedException)
{
if (bootFailedException == null)
throw new BootFailedException(DefaultMessage);
// see https://stackoverflow.com/questions/57383
// would that be the correct way to do it?
//ExceptionDispatchInfo.Capture(bootFailedException).Throw();
Exception e = bootFailedException;
var m = new StringBuilder();
m.Append(DefaultMessage);
while (e != null)
{
m.Append($"\n\n-> {e.GetType().FullName}: {e.Message}");
if (string.IsNullOrWhiteSpace(e.StackTrace) == false)
m.Append($"\n{e.StackTrace}");
e = e.InnerException;
}
throw new BootFailedException(m.ToString());
}
}
}