// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Diagnostics.CodeAnalysis; using EpicGames.Core; using Microsoft.Extensions.Logging; using UnrealBuildBase; // This namespace is intentional for backwards compatibility. // BuildException will eventually be marked Obsolete in favor of BuildLogEventException namespace UnrealBuildTool { /// /// Base class for exceptions thrown by UnrealBuildTool and AutomationTool /// [SuppressMessage("Naming", "CA1724:Type names should not match namespaces", Justification = "Renaming would break public api")] public class BuildException : Exception { /// /// Constructor /// /// The error message to display. public BuildException(string Message) : base(Message) { } /// /// Constructor which wraps another exception /// /// An inner exception to wrap /// The error message to display. public BuildException(Exception? InnerException, string Message) : base(Message, InnerException) { } /// /// Constructor /// /// Formatting string for the error message /// Arguments for the formatting string public BuildException(string Format, params object?[] Arguments) : base(String.Format(Format, Arguments)) { } /// /// Constructor which wraps another exception /// /// The inner exception being wrapped /// Format for the message string /// Format arguments public BuildException(Exception InnerException, string Format, params object?[] Arguments) : base(String.Format(Format, Arguments), InnerException) { } /// /// Log BuildException with a provided ILogger /// /// The ILogger to use to log this exception public virtual void LogException(ILogger Logger) { Logger.LogError(this, "{Ex}", ExceptionUtils.FormatException(this)); Logger.LogDebug(this, "{Ex}", ExceptionUtils.FormatExceptionDetails(this)); } /// /// Returns the string representing the exception. Our build exceptions do not show the callstack since they are used to report known error conditions. /// /// Message for the exception public override string ToString() { return Message; } } }