ExceptHandler¶
- class astroid.nodes.ExceptHandler(lineno: int | None, col_offset: int | None, parent: NodeNG | None, *, end_lineno: int | None, end_col_offset: int | None)[source]¶
Bases:
MultiLineBlockNode,AssignTypeNode,StatementClass representing an
ast.ExceptHandler. node.An
ExceptHandleris anexceptblock on a try-except.>>> import astroid >>> node = astroid.extract_node(''' ... try: ... do_something() ... except Exception as error: ... print("Error!") ... ''') >>> node <Try l.2 at 0x...> >>> node.handlers [<ExceptHandler l.4 at 0x...>]
- assigned_stmts(**kwargs: _P.kwargs) Generator[InferenceResult]¶
Returns the assigned statement (non inferred) according to the assignment type. See astroid/protocols.py for actual implementation.
- catch(exceptions: list[str] | None) bool[source]¶
Check if this node handles any of the given
- Parameters:
exceptions – The names of the exceptions to check for.
- name: AssignName | None¶
The name that the caught exception is assigned to.