2016-09-01 19:06:08 +02:00
using System ;
2019-07-19 10:22:44 +02:00
using System.Runtime.Serialization ;
2018-10-25 15:07:04 +02:00
using System.Text ;
2016-09-01 19:06:08 +02:00
2021-02-18 11:06:02 +01:00
namespace Umbraco.Cms.Core.Exceptions
2016-09-01 19:06:08 +02:00
{
/// <summary>
2018-10-25 15:07:04 +02:00
/// An exception that is thrown if the Umbraco application cannot boot.
2016-09-01 19:06:08 +02:00
/// </summary>
2019-07-19 10:22:44 +02:00
/// <seealso cref="System.Exception" />
[Serializable]
2016-09-01 19:06:08 +02:00
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
2016-09-01 19:06:08 +02:00
/// <summary>
2019-07-19 10:22:44 +02:00
/// Initializes a new instance of the <see cref="BootFailedException" /> class.
2016-09-01 19:06:08 +02:00
/// </summary>
2019-07-19 10:22:44 +02:00
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>
2016-09-01 19:06:08 +02:00
public BootFailedException ( string message )
: base ( message )
{ }
2016-09-11 19:57:33 +02:00
/// <summary>
2019-07-19 10:22:44 +02:00
/// Initializes a new instance of the <see cref="Exception" /> class with a specified error message
2016-09-11 19:57:33 +02:00
/// and a reference to the inner exception which is the cause of this exception.
/// </summary>
2019-07-19 10:22:44 +02:00
/// <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 )
2016-09-11 19:57:33 +02:00
{ }
2018-10-25 15:07:04 +02:00
/// <summary>
2019-07-19 10:22:44 +02:00
/// Rethrows a captured <see cref="BootFailedException" />.
2018-10-25 15:07:04 +02:00
/// </summary>
2019-07-19 10:22:44 +02:00
/// <param name="bootFailedException">The boot failed exception.</param>
2021-02-18 11:06:02 +01:00
/// <exception cref="BootFailedException">
2019-07-19 10:22:44 +02:00
/// </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 ( ) ) ;
}
2016-09-01 19:06:08 +02:00
}
2017-07-20 11:21:28 +02:00
}