Files
predavanja/Events-WebApi/Events.WebAPI/Util/Extensions/ExceptionExtensions.cs
2026-05-10 23:39:55 +02:00

29 lines
911 B
C#

using System.Text;
namespace Events.WebAPI.Util.Extensions
{
/// <summary>
/// Class with useful extensions for exceptions handling
/// </summary>
public static class ExceptionExtensions
{
/// <summary>
/// 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.
/// </summary>
/// <param name="exc">Exception which message hiearchy should be obtained</param>
/// <returns>String containing all exception hierarchy messages</returns>
public static string CompleteExceptionMessage(this Exception? exc)
{
StringBuilder sb = new();
while (exc != null)
{
sb.AppendLine(exc.Message);
exc = exc.InnerException;
}
return sb.ToString();
}
}
}