Files
Umbraco-CMS/src/Umbraco.Core/Exceptions/BootFailedException.cs

84 lines
3.4 KiB
C#
Raw Normal View History

using System;
using System.Runtime.Serialization;
2018-10-25 15:07:04 +02:00
using System.Text;
namespace Umbraco.Cms.Core.Exceptions
{
/// <summary>
2018-10-25 15:07:04 +02:00
/// An exception that is thrown if the Umbraco application cannot boot.
/// </summary>
/// <seealso cref="System.Exception" />
[Serializable]
public class BootFailedException : Exception
{
2017-05-31 15:25:07 +02:00
/// <summary>
/// Defines the default boot failed exception message.
/// </summary>
2019-02-05 19:59:13 +01:00
public const string DefaultMessage = "Boot failed: Umbraco cannot run. See Umbraco's log file for more details.";
2017-05-31 15:25:07 +02:00
/// <summary>
/// Initializes a new instance of the <see cref="BootFailedException" /> class.
/// </summary>
public BootFailedException()
{ }
/// <summary>
/// Initializes a new instance of the <see cref="Exception" /> class with a specified error message.
/// </summary>
/// <param name="message">The message that describes the error.</param>
public BootFailedException(string message)
: base(message)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="Exception" /> class with a specified error message
/// and a reference to the inner exception which is the cause of this exception.
/// </summary>
/// <param name="message">The message that describes the error.</param>
/// <param name="innerException">The inner exception, or null.</param>
public BootFailedException(string message, Exception innerException)
: base(message, innerException)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="BootFailedException" /> class.
/// </summary>
/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo" /> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext" /> that contains contextual information about the source or destination.</param>
protected BootFailedException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
2018-10-25 15:07:04 +02:00
/// <summary>
/// Rethrows a captured <see cref="BootFailedException" />.
2018-10-25 15:07:04 +02:00
/// </summary>
/// <param name="bootFailedException">The boot failed exception.</param>
/// <exception cref="BootFailedException">
/// </exception>
/// <remarks>
/// The exception can be null, in which case a default message is used.
/// </remarks>
2018-10-25 15:07:04 +02:00
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());
}
}
2017-07-20 11:21:28 +02:00
}