AddError() public method

将异常添加到当前 异常集合中。
public AddError ( System e ) : void
e System 异常
return 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);
            }
        }