AddError() публичный Метод

将异常添加到当前 异常集合中。
public AddError ( System e ) : void
e System 异常
Результат void
Пример #1
0
 /// <inheritdoc />
 public virtual void Render(TextWriter writer, TemplateContext context)
 {
     if (templateResult == null)
     {
         if (this.Context.Mode == EngineMode.Interpreted)
         {
             templateResult = context.InterpretTemplate(this.TemplateKey, this.reader);
         }
         else
         {
             templateResult = context.CompileTemplate(this.TemplateKey, this.reader);
         }
         if (templateResult == null)
         {
             throw new TemplateException($"template error.");
         }
     }
     try
     {
         templateResult.Render(writer, context);
     }
     catch (System.Exception e)
     {
         context.AddError(e);
     }
 }
Пример #2
0
 /// <summary>
 /// Throw exception.
 /// </summary>
 /// <param name="ctx"></param>
 /// <param name="e">Represents errors that occur during application execution.</param>
 /// <param name="tag">Represents errors tag.</param>
 /// <param name="writer">See the <see cref="System.IO.TextWriter"/>.</param>
 public static void ThrowException(this TemplateContext ctx, TemplateException e, ITag tag, System.IO.TextWriter writer)
 {
     ctx.AddError(e);
     if (ctx.ThrowExceptions)
     {
         writer.Write(tag.ToSource());
     }
 }
Пример #3
0
 /// <summary>
 /// Throw exception.
 /// </summary>
 /// <param name="ctx"></param>
 /// <param name="e">Represents errors that occur during application execution.</param>
 /// <param name="tag">Represents errors tag.</param>
 /// <param name="writer">See the <see cref="System.IO.TextWriter"/>.</param>
 public static async Task ThrowExceptionAsync(this TemplateContext ctx, TemplateException e, ITag tag, System.IO.TextWriter writer)
 {
     ctx.AddError(e);
     if (!ctx.ThrowExceptions)
     {
         await writer.WriteAsync(tag.ToSource());
     }
 }
Пример #4
0
        /// <inheritdoc />
        public Task RenderAsync(TextWriter writer, TemplateContext context, CancellationToken cancellationToken = default)
        {
            cancellationToken.ThrowIfCancellationRequested();

            var t = context.CompileTemplate(this.TemplateKey, this.reader);

            if (t == null)
            {
                throw new TemplateException($"template error.");
            }
            try
            {
                return(t.RenderAsync(writer, context, cancellationToken));
            }
            catch (System.Exception e)
            {
                context.AddError(e);
                return(Task.FromException(e));
            }
        }
Пример #5
0
        /// <inheritdoc />
        public virtual void Render(TextWriter writer, TemplateContext context)
        {
            var text = this.TemplateContent;
            var t    = context.Options.CompilerResults.GetOrAdd(this.TemplateKey, (key) =>
            {
                return(TemplateCompiler.Compile(key, text, context.Options, (ctx) =>
                {
                    context.CopyTo(ctx);
                }));
            });

            if (t == null)
            {
                throw new Exception.TemplateException($"compile error.");
            }
            try
            {
                t.Render(writer, context);
            }
            catch (System.Exception e)
            {
                context.AddError(e);
            }
        }