using System; using System.Runtime.Serialization; using System.Text; namespace Umbraco.Cms.Core.Exceptions { /// /// An exception that is thrown if the Umbraco application cannot boot. /// /// [Serializable] public class BootFailedException : Exception { /// /// Defines the default boot failed exception message. /// public const string DefaultMessage = "Boot failed: Umbraco cannot run. See Umbraco's log file for more details."; /// /// Initializes a new instance of the class. /// public BootFailedException() { } /// /// Initializes a new instance of the class with a specified error message. /// /// The message that describes the error. public BootFailedException(string message) : base(message) { } /// /// Initializes a new instance of the class with a specified error message /// and a reference to the inner exception which is the cause of this exception. /// /// The message that describes the error. /// The inner exception, or null. public BootFailedException(string message, Exception innerException) : base(message, innerException) { } /// /// Initializes a new instance of the class. /// /// The that holds the serialized object data about the exception being thrown. /// The that contains contextual information about the source or destination. protected BootFailedException(SerializationInfo info, StreamingContext context) : base(info, context) { } /// /// Rethrows a captured . /// /// The boot failed exception. /// /// /// /// The exception can be null, in which case a default message is used. /// 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()); } } }