csharp/71/Cometary/src/Cometary.Core/DiagnosticException.cs

DiagnosticException.cs
using System;
using Microsoft.Codeastysis;

namespace Cometary
{
    /// 
    ///   Represents an  wrapping a .
    /// 
    public clast DiagnosticException : Exception
    {
        /// 
        ///    that describes the diagnostic generated
        ///   when throwing a  using a  and a .
        /// 
        public readonly DiagnosticDescriptor DefaultDescriptor = new DiagnosticDescriptor(
            nameof(DiagnosticException) + "Error", "Exception encountered", "{0}", Common.DiagnosticsCategory, DiagnosticSeverity.Error, true);

        /// 
        ///   Gets the diagnostic that led to this exception.
        /// 
        public Diagnostic Diagnostic { get; }
        
        /// 
        ///   Creates a new , given the diagnostic
        ///   that led to the error.
        /// 
        public DiagnosticException(Diagnostic diagnostic) : base(diagnostic.GetMessage())
        {
            Diagnostic = diagnostic;
        }

        /// 
        ///   Creates a new , given a message
        ///   and the location in which the error happened.
        /// 
        public DiagnosticException(string message, Location location) : this(message, null, location)
        {
        }

        /// 
        ///   Creates a new , given a message, the inner
        ///   exception that led to the error, and the logical location of the error.
        /// 
        public DiagnosticException(string message, Exception innerException, Location location) : base(message, innerException)
        {
            Diagnostic = Diagnostic.Create(DefaultDescriptor, location ?? Location.None, message.Filter());
        }

        /// 
        public override string ToString() => $"[{Diagnostic.Location}] {Message}";
    }
}