private static ITranslatable GetExceptionClauseOrNullFor(CatchBlock catchBlock, ITranslationContext context) { if (ExceptionUsageFinder.IsVariableUsed(catchBlock)) { return((catchBlock.Filter != null) ? new FilteredExceptionClause(catchBlock, context) : new NamedVariableExceptionClause(catchBlock, context)); } return((catchBlock.Test != typeof(Exception)) ? new AnonymousExceptionClause(catchBlock, context) : null); }
private static string GetExceptionClause(CatchBlock catchBlock, TranslationContext context) { var exceptionTypeName = catchBlock.Test.GetFriendlyName(); if (ExceptionUsageFinder.IsVariableUsed(catchBlock)) { var filter = (catchBlock.Filter != null) ? " when " + context.Translate(catchBlock.Filter) : null; return($" ({exceptionTypeName} {catchBlock.Variable.Name})" + filter); } return((catchBlock.Test != typeof(Exception)) ? $" ({exceptionTypeName})" : null); }
public static bool IsVariableUsed(CatchBlock catchHandler) { if (catchHandler.Variable == null) { return(false); } var visitor = new ExceptionUsageFinder(catchHandler); visitor.Visit(catchHandler.Filter); if (!visitor._usageFound) { visitor.Visit(catchHandler.Body); } return(visitor._usageFound); }