using System.Text;
namespace Events.MVC.Util.Extensions
{
///
/// Class with useful extensions for exceptions handling
///
public static class ExceptionExtensions
{
///
/// return complete hierarchy of an exception. It checks whether the exception has inner exception,
/// and if it has, then it appends inner exception message.
/// Then it looks for inner exception of the inner exceptions, and so on.
///
/// Exception which message hiearchy should be obtained
/// String containing all exception hierarchy messages
public static string CompleteExceptionMessage(this Exception? exc)
{
StringBuilder sb = new();
while (exc != null)
{
sb.AppendLine(exc.Message);
exc = exc.InnerException;
}
return sb.ToString();
}
}
}