/// <summary> /// Write out a runtime error message for a Grace exception /// according to the configuration provided by the front end. /// </summary> /// <param name="gep">Exception packet to print</param> /// <remarks> /// The message is written to the <c cref="OutputSink"> /// OutputSink</c> configured by the front end. /// </remarks> /// <seealso cref="WriteError" /> public static void WriteException(GraceExceptionPacket gep) { if (!Console.IsErrorRedirected) { Console.ForegroundColor = ConsoleColor.Red; } sink.WriteLine(gep.Description); if (!Console.IsErrorRedirected) { Console.ResetColor(); } }
/// <summary> /// Raise a Grace exception for a particular error. /// </summary> /// <param name="ctx">Evaluation context to raise from</param> /// <param name="code">Error code</param> /// <param name="vars">Dictionary from variable names to /// values to insert in the message in their place.</param> /// <param name="localDescription">A description of the error /// given at the site of generation, which will be used if no /// user error message for <paramref name="code" /> is found. /// </param> /// <remarks> /// A new <c cref="GraceExceptionPacket">GraceExceptionPacket /// </c> is created and thrown with the retrieved method and /// current call stack. /// </remarks> /// <seealso cref="WriteException" /> public static void RaiseError(EvaluationContext ctx, string code, Dictionary <string, string> vars, string localDescription) { string baseMessage = GetMessage(code, vars) ?? localDescription; var parts = baseMessage.Split(new[] { ": " }, 2, StringSplitOptions.None); var kind = parts[0]; var msg = parts[1]; msg = FormatMessage(msg, vars); GraceExceptionPacket.Throw(kind, code + ": " + msg, ctx.GetStackTrace()); }