当前位置: 首页>>代码示例>>C#>>正文


C# CatchClause类代码示例

本文整理汇总了C#中CatchClause的典型用法代码示例。如果您正苦于以下问题:C# CatchClause类的具体用法?C# CatchClause怎么用?C# CatchClause使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CatchClause类属于命名空间,在下文中一共展示了CatchClause类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TryStatement

    public TryStatement(Statement statement, CatchClause catchClause, FinallyClause finallyClause)
    {
      Statement = statement;
      Catch = catchClause;
      Finally = finallyClause;
      SourceOffset = statement.SourceOffset;

      Use(Statement);
      Use(Catch);
      Use(Finally);

      m.Util.Diagnose.Debug.Assert(Catch != null || Finally != null, "SyntaxError: Missing catch or finally after try");
    }
开发者ID:reshadi2,项目名称:mcjs,代码行数:13,代码来源:TryStatement.cs

示例2: VisitCatchClause

			public override void VisitCatchClause(CatchClause catchClause)
			{
				base.VisitCatchClause(catchClause);
				var exceptionResolveResult = ctx.Resolve(catchClause.VariableNameToken) as LocalResolveResult;
				if (exceptionResolveResult == null)
					return;

				var catchVisitor = new CatchClauseVisitor(ctx, exceptionResolveResult.Variable);
				catchClause.Body.AcceptVisitor(catchVisitor);

				foreach (var throwStatement in catchVisitor.OffendingThrows) {
					var localThrowStatement = throwStatement;
					var title = ctx.TranslateString("The exception is rethrown with explicit usage of the variable");
					var action = new CodeAction(ctx.TranslateString("Change to 'throw;'"), script => {
						script.Replace(localThrowStatement, new ThrowStatement());
					});
					AddIssue(localThrowStatement, title, new [] { action });
				}
			}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:19,代码来源:ExceptionRethrowIssue.cs

示例3: VisitCatchClause

		public virtual object VisitCatchClause(CatchClause catchClause, object data) {
			Debug.Assert((catchClause != null));
			Debug.Assert((catchClause.TypeReference != null));
			Debug.Assert((catchClause.StatementBlock != null));
			Debug.Assert((catchClause.Condition != null));
			nodeStack.Push(catchClause.TypeReference);
			catchClause.TypeReference.AcceptVisitor(this, data);
			catchClause.TypeReference = ((TypeReference)(nodeStack.Pop()));
			nodeStack.Push(catchClause.StatementBlock);
			catchClause.StatementBlock.AcceptVisitor(this, data);
			catchClause.StatementBlock = ((Statement)(nodeStack.Pop()));
			nodeStack.Push(catchClause.Condition);
			catchClause.Condition.AcceptVisitor(this, data);
			catchClause.Condition = ((Expression)(nodeStack.Pop()));
			return null;
		}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:16,代码来源:AbstractAstTransformer.cs

示例4: ConvertCatch

			CatchClause ConvertCatch (Catch ctch) 
			{
				CatchClause result = new CatchClause ();
				var location = LocationsBag.GetLocations (ctch);
				if (location != null)
					result.AddChild (new CSharpTokenNode (Convert (location[0]), "catch".Length), CatchClause.Roles.Keyword);
				
				if (ctch.Type_expr != null) {
					if (location != null)
						result.AddChild (new CSharpTokenNode (Convert (location[1]), 1), CatchClause.Roles.LPar);
					
					result.AddChild ((INode)ctch.Type_expr.Accept (this), CatchClause.Roles.ReturnType);
					if (!string.IsNullOrEmpty (ctch.Name))
						result.AddChild (new Identifier (ctch.Name, Convert (location[1])), CatchClause.Roles.Identifier);
					
					if (location != null)
						result.AddChild (new CSharpTokenNode (Convert (location[2]), 1), CatchClause.Roles.RPar);
				}
				
				result.AddChild ((INode)ctch.Block.Accept (this), CatchClause.Roles.Body);
				
				return result;
			}
开发者ID:pgoron,项目名称:monodevelop,代码行数:23,代码来源:CSharpParser.cs

示例5: ConvertCatch

			CatchClause ConvertCatch(Catch ctch)
			{
				var result = new CatchClause();
				var location = LocationsBag.GetLocations(ctch);
				result.AddChild(new CSharpTokenNode(Convert(ctch.loc), CatchClause.CatchKeywordRole), CatchClause.CatchKeywordRole);
				if (ctch.TypeExpression != null) {
					if (location != null)
						result.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.LPar), Roles.LPar);
					
					if (ctch.TypeExpression != null)
						result.AddChild(ConvertToType(ctch.TypeExpression), Roles.Type);
					if (ctch.Variable != null && !string.IsNullOrEmpty(ctch.Variable.Name))
						result.AddChild(Identifier.Create(ctch.Variable.Name, Convert(ctch.Variable.Location)), Roles.Identifier);
					
					if (location != null && location.Count > 1)
						result.AddChild(new CSharpTokenNode(Convert(location [1]), Roles.RPar), Roles.RPar);
				}

				if (ctch.Block != null)
					result.AddChild((BlockStatement)ctch.Block.Accept(this), Roles.Body);
				
				return result;
			}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:23,代码来源:CSharpParser.cs

示例6: CompileCatchClause

		private JsBlockStatement CompileCatchClause(LocalResolveResult catchVariable, CatchClause catchClause, bool isCatchAll, bool isOnly) {
			SetRegion(catchClause.GetRegion());
			JsStatement variableDeclaration = null;
			if (!catchClause.VariableNameToken.IsNull) {
				JsExpression compiledAssignment;
				if (isCatchAll)	// If this is the only handler we need to construct the exception
					compiledAssignment = isOnly ? _runtimeLibrary.MakeException(JsExpression.Identifier(_variables[catchVariable.Variable].Name), this) : JsExpression.Identifier(_variables[catchVariable.Variable].Name);
				else
					compiledAssignment = _runtimeLibrary.Downcast(JsExpression.Identifier(_variables[catchVariable.Variable].Name), _compilation.FindType(KnownTypeCode.Exception), _resolver.Resolve(catchClause.Type).Type, this);

				variableDeclaration = JsStatement.Var(_variables[((LocalResolveResult)_resolver.Resolve(catchClause.VariableNameToken)).Variable].Name, compiledAssignment);
			}

			var result = CreateInnerCompiler().Compile(catchClause.Body);
			if (variableDeclaration != null)
				result = JsStatement.Block(new[] { variableDeclaration }.Concat(result.Statements));
			return result;
		}
开发者ID:chenxustu1,项目名称:SaltarelleCompiler,代码行数:18,代码来源:StatementCompiler.cs

示例7: VisitCatchClause

 public virtual void VisitCatchClause(CatchClause catchClause)
 {
     if (this.ThrowException)
     {
         throw (Exception)this.CreateException(catchClause);
     }
 }
开发者ID:fabriciomurta,项目名称:BridgeUnified,代码行数:7,代码来源:Visitor.Exception.cs

示例8: VisitCatchClause

		public virtual void VisitCatchClause(CatchClause catchClause)
		{
			StartNode(catchClause);
			WriteKeyword(CatchClause.CatchKeywordRole);
			if (!catchClause.Type.IsNull) {
				Space(policy.SpaceBeforeCatchParentheses);
				LPar();
				Space(policy.SpacesWithinCatchParentheses);
				catchClause.Type.AcceptVisitor(this);
				if (!string.IsNullOrEmpty(catchClause.VariableName)) {
					Space();
					WriteIdentifier(catchClause.VariableNameToken);
				}
				Space(policy.SpacesWithinCatchParentheses);
				RPar();
			}
			if (!catchClause.Condition.IsNull) {
				Space();
				WriteKeyword(CatchClause.WhenKeywordRole);
				Space(policy.SpaceBeforeIfParentheses);
				LPar();
				Space(policy.SpacesWithinIfParentheses);
				catchClause.Condition.AcceptVisitor(this);
				Space(policy.SpacesWithinIfParentheses);
				RPar();
			}
			WriteBlock(catchClause.Body, policy.StatementBraceStyle);
			EndNode(catchClause);
		}
开发者ID:icsharpcode,项目名称:NRefactory,代码行数:29,代码来源:CSharpOutputVisitor.cs

示例9: GetWatchInstrument

	        static Statement GetWatchInstrument (string id, Expression expr)
			{
				var r = new MemberReferenceExpression (
					new MemberReferenceExpression (
						new MemberReferenceExpression (
							new IdentifierExpression ("Continuous"), "Server"), "WatchStore"), "Record");
				var i = new ExpressionStatement (new InvocationExpression (r, new PrimitiveExpression (id), expr));
				var t = new TryCatchStatement ();
				t.TryBlock = new BlockStatement ();
				t.TryBlock.Statements.Add (i);
				var c = new CatchClause ();
				c.Body = new BlockStatement ();
				t.CatchClauses.Add (c);
				return t;
			}
开发者ID:mono,项目名称:Continuous,代码行数:15,代码来源:ContinuousEnv.MonoDevelop.cs

示例10: TransformNode

		IEnumerable<Statement> TransformNode(ILNode node)
		{
			if (node is ILLabel) {
				yield return new Ast.LabelStatement { Label = ((ILLabel)node).Name };
			} else if (node is ILExpression) {
				List<ILRange> ilRanges = ((ILExpression)node).GetILRanges();
				AstNode codeExpr = TransformExpression((ILExpression)node);
				if (codeExpr != null) {
					codeExpr = codeExpr.WithAnnotation(ilRanges);
					if (codeExpr is Ast.Expression) {
						yield return new Ast.ExpressionStatement { Expression = (Ast.Expression)codeExpr };
					} else if (codeExpr is Ast.Statement) {
						yield return (Ast.Statement)codeExpr;
					} else {
						throw new Exception();
					}
				}
			} else if (node is ILWhileLoop) {
				ILWhileLoop ilLoop = (ILWhileLoop)node;
				WhileStatement whileStmt = new WhileStatement() {
					Condition = ilLoop.Condition != null ? (Expression)TransformExpression(ilLoop.Condition) : new PrimitiveExpression(true),
					EmbeddedStatement = TransformBlock(ilLoop.BodyBlock)
				};
				yield return whileStmt;
			} else if (node is ILCondition) {
				ILCondition conditionalNode = (ILCondition)node;
				bool hasFalseBlock = conditionalNode.FalseBlock.EntryGoto != null || conditionalNode.FalseBlock.Body.Count > 0;
				yield return new Ast.IfElseStatement {
					Condition = (Expression)TransformExpression(conditionalNode.Condition),
					TrueStatement = TransformBlock(conditionalNode.TrueBlock),
					FalseStatement = hasFalseBlock ? TransformBlock(conditionalNode.FalseBlock) : null
				};
			} else if (node is ILSwitch) {
				ILSwitch ilSwitch = (ILSwitch)node;
				SwitchStatement switchStmt = new SwitchStatement() { Expression = (Expression)TransformExpression(ilSwitch.Condition) };
				foreach (var caseBlock in ilSwitch.CaseBlocks) {
					SwitchSection section = new SwitchSection();
					if (caseBlock.Values != null) {
						section.CaseLabels.AddRange(caseBlock.Values.Select(i => new CaseLabel() { Expression = AstBuilder.MakePrimitive(i, ilSwitch.Condition.InferredType) }));
					} else {
						section.CaseLabels.Add(new CaseLabel());
					}
					section.Statements.Add(TransformBlock(caseBlock));
					switchStmt.SwitchSections.Add(section);
				}
				yield return switchStmt;
			} else if (node is ILTryCatchBlock) {
				ILTryCatchBlock tryCatchNode = ((ILTryCatchBlock)node);
				var tryCatchStmt = new Ast.TryCatchStatement();
				tryCatchStmt.TryBlock = TransformBlock(tryCatchNode.TryBlock);
				foreach (var catchClause in tryCatchNode.CatchBlocks) {
					tryCatchStmt.CatchClauses.Add(
						new Ast.CatchClause {
							Type = AstBuilder.ConvertType(catchClause.ExceptionType),
							VariableName = catchClause.ExceptionVariable == null ? null : catchClause.ExceptionVariable.Name,
							Body = TransformBlock(catchClause)
						});
				}
				if (tryCatchNode.FinallyBlock != null)
					tryCatchStmt.FinallyBlock = TransformBlock(tryCatchNode.FinallyBlock);
				if (tryCatchNode.FaultBlock != null) {
					CatchClause cc = new CatchClause();
					cc.Body = TransformBlock(tryCatchNode.FaultBlock);
					cc.Body.Add(new ThrowStatement()); // rethrow
					tryCatchStmt.CatchClauses.Add(cc);
				}
				yield return tryCatchStmt;
			} else if (node is ILBlock) {
				yield return TransformBlock((ILBlock)node);
			} else if (node is ILComment) {
				yield return new CommentStatement(((ILComment)node).Text).WithAnnotation(((ILComment)node).ILRanges);
			} else {
				throw new Exception("Unknown node type");
			}
		}
开发者ID:hlesesne,项目名称:ILSpy,代码行数:75,代码来源:AstMethodBodyBuilder.cs

示例11: VisitCatchClause

		public virtual object VisitCatchClause(CatchClause catchClause, object data) {
			Debug.Assert((catchClause != null));
			Debug.Assert((catchClause.TypeReference != null));
			Debug.Assert((catchClause.StatementBlock != null));
			Debug.Assert((catchClause.Condition != null));
			catchClause.TypeReference.AcceptVisitor(this, data);
			catchClause.StatementBlock.AcceptVisitor(this, data);
			return catchClause.Condition.AcceptVisitor(this, data);
		}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:9,代码来源:AbstractASTVisitor.cs

示例12: VisitCatchClause

        public void VisitCatchClause(CatchClause catchClause)
        {
            JsonObject visitCatch = new JsonObject();
            visitCatch.Comment = "VisitCatchClause";

            AddKeyword(visitCatch, "catch-keyword", CatchClause.CatchKeywordRole);

            if (!catchClause.Type.IsNull)
            {
                visitCatch.AddJsonValue("type-info", GenTypeInfo(catchClause.Type));
                if (!string.IsNullOrEmpty(catchClause.VariableName))
                {
                    visitCatch.AddJsonValue("identifier", GetIdentifier(catchClause.VariableNameToken));
                }
            }

            visitCatch.AddJsonValue("catch-body", GenStatement(catchClause.Body));

            Push(visitCatch);
        }
开发者ID:CompilerKit,项目名称:CodeWalk,代码行数:20,代码来源:AstCsToJson.cs

示例13: VisitTryCatchStatement

			public override void VisitTryCatchStatement (TryCatchStatement tryCatchStatement)
			{
				base.VisitTryCatchStatement (tryCatchStatement);

				var catches = tryCatchStatement.CatchClauses.ToList ();
				if (catches.Count == 0)
					return;

				var varName = catches.Where (x => !string.IsNullOrEmpty (x.VariableName)).Select (x => x.VariableName).FirstOrDefault ();
				if (varName == null) {
					varName = "_ex";
				}

				//
				// Fix first
				//
				foreach (var c in catches) {
					if (string.IsNullOrEmpty (c.VariableName)) {
						c.VariableName = varName;
					}
				}

				//
				// Merge them
				//
				if (catches.Count > 0) {
					var body = new BlockStatement ();
					var newCatch = new CatchClause {
						VariableName = varName,
						Body = body,
					};

					IfElseStatement lastIf = null;

					foreach (var c in catches) {

						var cbody = c.Body;
						cbody.Remove ();

						var iff = new IfElseStatement (GetNotNullTypeCheck (varName, c.Type), cbody);

						if (lastIf == null)
							body.Add (iff);
						else
							lastIf.FalseStatement = iff;

						lastIf = iff;

						c.Remove ();
					}

					var rethrow = new ThrowStatement (new IdentifierExpression (varName));

					if (lastIf == null)
						body.Add (rethrow);
					else
						lastIf.FalseStatement = rethrow;

					tryCatchStatement.CatchClauses.Add (newCatch);
				}
			}
开发者ID:RReverser,项目名称:Netjs,代码行数:61,代码来源:CsToTs.cs

示例14: VisitCatchClause

 public void VisitCatchClause(CatchClause node)
 {
     VisitChildren(node);
 }
开发者ID:evanw,项目名称:minisharp,代码行数:4,代码来源:Lower.cs

示例15: VisitCatchClause

		public virtual object VisitCatchClause(CatchClause catchClause, object data) {
			throw new global::System.NotImplementedException("CatchClause");
		}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:3,代码来源:NotImplementedAstVisitor.cs


注:本文中的CatchClause类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。