using System; using System.CodeDom.Compiler; using System.Runtime.Serialization; using System.Text; namespace Chernobyl.Plugin.Exceptions { /// /// An exception that is thrown when the compilation of scripts or other /// resources produces an error. /// public class CompileErrorException : Exception { /// /// Initializes a new instance of the /// class which uses the . /// /// The that contain /// information about the compilation in question. public CompileErrorException(CompilerResults errors) : this(DefaultMessage, errors) { } /// /// Initializes a new instance of the /// class. /// /// The error message that explains the reason for /// the exception. /// The that contain /// information about the compilation in question. public CompileErrorException(string message, CompilerResults results) : base(message) { Results = results; } /// /// Initializes a new instance of the class. /// /// The error message that explains the reason for /// the exception. /// The that contain /// information about the compilation in question. /// The exception that is the cause of the /// current exception, or a null reference (Nothing in Visual Basic) if /// no inner exception is specified. public CompileErrorException(string message, CompilerResults results, Exception innerException) : base(message, innerException) { Results = results; } /// /// 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. /// The /// parameter is null. /// The class name is null or /// is zero (0). public CompileErrorException(SerializationInfo info, StreamingContext context) : base(info, context) { } /// /// The that contain information about the /// compilation in question. /// public CompilerResults Results { get; private set; } /// /// Gets a message that describes the current exception. /// /// /// /// The error message that explains the reason for the exception, or an /// empty string(""). /// public override string Message { get { if(_message == null) { // add the errors to the exception message. StringBuilder errorBuilder = new StringBuilder(base.Message); errorBuilder.Append(" The following errors occurred during compilation:"); errorBuilder.AppendLine(); foreach (CompilerError error in Results.Errors) errorBuilder.AppendLine(error.ToString()); _message = errorBuilder.ToString(); } return _message; } } /// /// The default message of this exception. This message is used if a /// message isn't provided to a constructor of this class. /// public const string DefaultMessage = "Failed to compile the resource, " + "errors were found during its compilation."; /// /// The that contains the formatted message /// returned by , stored for optimization /// purposes. /// string _message; } }