def _declares_catch_for_exceptions( java_dest: str, exceptions_list: list, open_msg: str, closed_msg: str, exclude: list = None) -> bool: """Search for the declaration of catch for the given exceptions.""" any_exception = L_VAR_CHAIN_NAME provided_exception = MatchFirst( [Keyword(exception) for exception in exceptions_list]) exception_group = delimitedList(expr=any_exception, delim='|') exception_group.addCondition( # Ensure that at least one exception in the group is the provided one lambda tokens: any(provided_exception.matches(tok) for tok in tokens)) grammar = Suppress(Keyword('catch')) + nestedExpr( opener='(', closer=')', content=( exception_group + Suppress(Optional(L_VAR_NAME)))) grammar.ignore(javaStyleComment) grammar.ignore(L_STRING) grammar.ignore(L_CHAR) try: matches = lang.path_contains_grammar(grammar, java_dest, LANGUAGE_SPECS, exclude) except FileNotFoundError: show_unknown('File does not exist', details=dict(code_dest=java_dest)) else: if matches: show_open(open_msg, details=dict(matched=matches)) return True show_close(closed_msg, details=dict(code_dest=java_dest)) return False