本文整理汇总了C#中TryCatchStatement类的典型用法代码示例。如果您正苦于以下问题:C# TryCatchStatement类的具体用法?C# TryCatchStatement怎么用?C# TryCatchStatement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TryCatchStatement类属于命名空间,在下文中一共展示了TryCatchStatement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitTryCatchStatement
public override object VisitTryCatchStatement(TryCatchStatement tryCatchStatement, object data)
{
if(tryCatchStatement.CatchClauses.Count > 0 && !tryCatchStatement.FinallyBlock.IsNull)
{
UnlockWith(tryCatchStatement);
}
return base.VisitTryCatchStatement(tryCatchStatement, data);
}
示例2: VisitTryCatchStatement
public override object VisitTryCatchStatement(TryCatchStatement tryCatchStatement, object data)
{
if (tryCatchStatement.CatchClauses.Count > 5)
{
UnlockWith(tryCatchStatement);
}
return base.VisitTryCatchStatement(tryCatchStatement, data);
}
示例3: VisitTryCatchStatement
public override object VisitTryCatchStatement(TryCatchStatement tryCatchStatement, object data)
{
var defaultCatchClause = tryCatchStatement.CatchClauses.FirstOrDefault(a => a.Type.IsNull);
if(defaultCatchClause != null)
{
UnlockWith(defaultCatchClause);
}
return base.VisitTryCatchStatement(tryCatchStatement, data);
}
示例4: TestEmptyFinallyDoesNotMatchNullFinally
public void TestEmptyFinallyDoesNotMatchNullFinally()
{
TryCatchStatement c1 = new TryCatchStatement {
TryBlock = new BlockStatement(),
CatchClauses = { new CatchClause { Body = new BlockStatement() } }
};
TryCatchStatement c2 = new TryCatchStatement {
TryBlock = new BlockStatement(),
CatchClauses = { new CatchClause { Body = new BlockStatement() } },
FinallyBlock = new BlockStatement()
};
Assert.IsFalse(c1.IsMatch(c2));
Assert.IsFalse(c2.IsMatch(c1)); // and vice versa
}
示例5: VisitTryCatchStatement
public override object VisitTryCatchStatement(TryCatchStatement tryCatchStatement, object data)
{
if (tryCatchStatement.CatchClauses.Count > 0)
{
foreach (CatchClause catchClause in tryCatchStatement.CatchClauses)
{
var throwStatement = catchClause.Body.Statements.FirstOrDefault(a => a is ThrowStatement);
if(throwStatement != null)
{
UnlockWith(throwStatement);
}
}
}
return base.VisitTryCatchStatement(tryCatchStatement, data);
}
示例6: VisitTryCatchStatement
public override void VisitTryCatchStatement(TryCatchStatement tryCatchStatement)
{
var redundantCatchClauses = new List<CatchClause>();
bool hasNonRedundantCatch = false;
foreach (var catchClause in tryCatchStatement.CatchClauses) {
if (IsRedundant(catchClause)) {
redundantCatchClauses.Add(catchClause);
} else {
hasNonRedundantCatch = true;
}
}
if (hasNonRedundantCatch || !tryCatchStatement.FinallyBlock.IsNull) {
AddIssuesForClauses(redundantCatchClauses);
} else {
AddIssueForTryCatchStatement(tryCatchStatement);
}
}
示例7: VisitTryCatchStatement
public virtual void VisitTryCatchStatement(TryCatchStatement tryCatchStatement)
{
if (this.ThrowException)
{
throw (Exception)this.CreateException(tryCatchStatement);
}
}
示例8: VisitTryCatchStatement
public virtual void VisitTryCatchStatement(TryCatchStatement tryCatchStatement)
{
StartNode(tryCatchStatement);
WriteKeyword(TryCatchStatement.TryKeywordRole);
WriteBlock(tryCatchStatement.TryBlock, policy.StatementBraceStyle);
foreach (var catchClause in tryCatchStatement.CatchClauses) {
if (policy.CatchNewLinePlacement == NewLinePlacement.SameLine)
Space();
else
NewLine();
catchClause.AcceptVisitor(this);
}
if (!tryCatchStatement.FinallyBlock.IsNull) {
if (policy.FinallyNewLinePlacement == NewLinePlacement.SameLine)
Space();
else
NewLine();
WriteKeyword(TryCatchStatement.FinallyKeywordRole);
WriteBlock(tryCatchStatement.FinallyBlock, policy.StatementBraceStyle);
}
NewLine();
EndNode(tryCatchStatement);
}
示例9: VisitTryCatchStatement
public override void VisitTryCatchStatement(TryCatchStatement tryCatchStatement)
{
if (!tryCatchStatement.TryBlock.IsNull) {
FixEmbeddedStatment(policy.StatementBraceStyle, BraceForcement.DoNotChange, tryCatchStatement.TryBlock);
}
foreach (CatchClause clause in tryCatchStatement.CatchClauses) {
PlaceOnNewLine(policy.PlaceCatchOnNewLine, clause.CatchToken);
if (!clause.LParToken.IsNull) {
ForceSpacesBefore(clause.LParToken, policy.SpaceBeforeCatchParentheses);
ForceSpacesAfter(clause.LParToken, policy.SpacesWithinCatchParentheses);
ForceSpacesBefore(clause.RParToken, policy.SpacesWithinCatchParentheses);
}
FixEmbeddedStatment(policy.StatementBraceStyle, BraceForcement.DoNotChange, clause.Body);
}
if (!tryCatchStatement.FinallyBlock.IsNull) {
PlaceOnNewLine(policy.PlaceFinallyOnNewLine, tryCatchStatement.FinallyToken);
FixEmbeddedStatment(policy.StatementBraceStyle, BraceForcement.DoNotChange, tryCatchStatement.FinallyBlock);
}
}
示例10: VisitTryCatchStatement
public virtual void VisitTryCatchStatement(TryCatchStatement tryCatchStatement)
{
VisitBlock(tryCatchStatement.TryBlock);
VisitBlock(tryCatchStatement.CatchBlock);
}
示例11: VisitTryCatchStatement
public override object VisitTryCatchStatement(TryCatchStatement tryCatchStatement, object data)
{
if (tryCatchStatement == null) {
return data;
}
if (tryCatchStatement.StatementBlock != null) {
tryCatchStatement.StatementBlock.AcceptVisitor(this, data);
}
if (tryCatchStatement.CatchClauses != null) {
foreach (CatchClause catchClause in tryCatchStatement.CatchClauses) {
if (catchClause != null) {
if (catchClause.TypeReference != null && catchClause.VariableName != null) {
AddVariable(catchClause.TypeReference,
catchClause.VariableName,
catchClause.StatementBlock.StartLocation,
catchClause.StatementBlock.EndLocation,
false, false, null, null);
}
catchClause.StatementBlock.AcceptVisitor(this, data);
}
}
}
if (tryCatchStatement.FinallyBlock != null) {
return tryCatchStatement.FinallyBlock.AcceptVisitor(this, data);
}
return data;
}
示例12: VisitTryCatchStatement
public virtual void VisitTryCatchStatement(TryCatchStatement tryCatchStatement)
{
StartNode(tryCatchStatement);
var oldRef = currentTryReference;
currentTryReference = new object();
WriteKeywordReference(TryCatchStatement.TryKeywordRole, currentTryReference);
tryCatchStatement.TryBlock.AcceptVisitor(this);
int count = 0;
foreach (var catchClause in tryCatchStatement.CatchClauses) {
if (count-- <= 0) {
cancellationToken.ThrowIfCancellationRequested();
count = CANCEL_CHECK_LOOP_COUNT;
}
catchClause.AcceptVisitor(this);
}
if (!tryCatchStatement.FinallyBlock.IsNull) {
WriteKeywordReference(TryCatchStatement.FinallyKeywordRole, currentTryReference);
tryCatchStatement.FinallyBlock.AcceptVisitor(this);
}
currentTryReference = oldRef;
EndNode(tryCatchStatement);
}
示例13: TryStatement
void TryStatement(
#line 3245 "VBNET.ATG"
out Statement tryStatement) {
#line 3247 "VBNET.ATG"
Statement blockStmt = null, finallyStmt = null;List<CatchClause> catchClauses = null;
Expect(203);
EndOfStmt();
Block(
#line 3250 "VBNET.ATG"
out blockStmt);
if (la.kind == 62 || la.kind == 100 || la.kind == 110) {
CatchClauses(
#line 3251 "VBNET.ATG"
out catchClauses);
}
if (la.kind == 110) {
lexer.NextToken();
EndOfStmt();
Block(
#line 3252 "VBNET.ATG"
out finallyStmt);
}
Expect(100);
Expect(203);
#line 3255 "VBNET.ATG"
tryStatement = new TryCatchStatement(blockStmt, catchClauses, finallyStmt);
}
示例14: VisitTryCatchStatement
public virtual void VisitTryCatchStatement (TryCatchStatement tryCatchStatement)
{
VisitChildren (tryCatchStatement);
}
示例15: Visit
public override object Visit (TryCatch tryCatchStatement)
{
var result = new TryCatchStatement ();
result.AddChild (new CSharpTokenNode (Convert (tryCatchStatement.loc), "try".Length), TryCatchStatement.TryKeywordRole);
result.AddChild ((INode)tryCatchStatement.Block.Accept (this), TryCatchStatement.TryBlockRole);
foreach (Catch ctch in tryCatchStatement.Specific) {
result.AddChild (ConvertCatch (ctch), TryCatchStatement.CatchClauseRole);
}
if (tryCatchStatement.General != null)
result.AddChild (ConvertCatch (tryCatchStatement.General), TryCatchStatement.CatchClauseRole);
return result;
}