public IEnumerable <Json> Mash(Json json, IMashContext context) { context = context.PushStack(this); context.Tick(); var result = new List <Json>(); try { foreach (var value in TryBody.Mash(json, context)) { result.Add(value); } } catch (JsonMasherException ex) { if (CatchBody != null) { foreach (var value in CatchBody.Mash(Json.String(ex.Message), context)) { result.Add(value); } } } return(result); }
/// <inheritdoc/> public override BlockCodegen Emit(BasicBlockBuilder BasicBlock) { if (CatchClauses.Count == 0) { return(TryBody.Emit(BasicBlock)); } var exceptionDataType = StructType(new[] { PointerType(Int8Type(), 0), Int32Type() }, false); var catchBlock = BasicBlock.CreateChildBlock("catch"); var catchLandingPadBlock = BasicBlock.CreateChildBlock("catch_landingpad"); var leaveBlock = BasicBlock.CreateChildBlock("leave"); // The try block is a regular block that jumps to the 'leave' block. // // try: // <try body> // br label %leave var tryCodegen = TryBody.Emit(BasicBlock.WithUnwindTarget(catchLandingPadBlock, catchBlock)); BuildBr(tryCodegen.BasicBlock.Builder, leaveBlock.Block); PopulateCatchBlock(catchBlock, leaveBlock); ItaniumCxxFinallyBlock.PopulateThunkLandingPadBlock(catchLandingPadBlock, catchBlock.Block, false); return(new BlockCodegen(leaveBlock, tryCodegen.Value)); }
/// <inheritdoc/> public override BlockCodegen Emit(BasicBlockBuilder BasicBlock) { var exceptionDataType = StructType(new[] { PointerType(Int8Type(), 0), Int32Type() }, false); var isPropagatingStorage = BasicBlock.FunctionBody.CreateEntryPointAlloca( Int1Type(), "exception_value_alloca"); var finallyBlock = BasicBlock.CreateChildBlock("finally"); var finallyLandingPadBlock = BasicBlock.CreateChildBlock("finally_landingpad"); var finallyExceptionBlock = BasicBlock.CreateChildBlock("finally_exception"); var leaveBlock = BasicBlock.CreateChildBlock("leave"); // The try block is a regular block that jumps to the finally block. // // try: // store i1 false, i1* %is_propagating_exception_alloca // <try body> // br label %finally BuildStore( BasicBlock.Builder, ConstInt(Int1Type(), 0, false), isPropagatingStorage); var tryCodegen = TryBody.Emit(BasicBlock.WithUnwindTarget(finallyLandingPadBlock, finallyExceptionBlock)); BuildBr(tryCodegen.BasicBlock.Builder, finallyBlock.Block); PopulateFinallyBlock(finallyBlock, leaveBlock, isPropagatingStorage); PopulateThunkLandingPadBlock(finallyLandingPadBlock, finallyExceptionBlock.Block, true); // The 'finally_exception' block is entered if an exception is propagating from // the 'try' block. It sets the 'is propagating' flag to 'true' and branches // to the finally block. // // finally_exception: // store i1 true, i1* %is_propagating_exception_alloca // br label %finally BuildStore( finallyExceptionBlock.Builder, ConstInt(Int1Type(), 1, false), isPropagatingStorage); BuildBr(finallyExceptionBlock.Builder, finallyBlock.Block); return(new BlockCodegen(leaveBlock, tryCodegen.Value)); }
public override void WriteTo(TextWriter w) { w.Write("try"); TryBody.WriteTo(w); if (CatchStatement != null) { w.Write("catch("); w.Write(CaughtErrorIdentifier); w.Write("){"); CatchStatement.WriteTo(w); w.Write("}"); } w.Write("finally{"); foreach (var stmt in FinallyStatements) { stmt.WriteTo(w); } w.Write("}"); }
public override void VisitChildren(IVisitor visitor) { TryBody.Visit(visitor); CatchBody.Visit(visitor); }