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
,Statement
Class representing an
ast.ExceptHandler
. node.An
ExceptHandler
is anexcept
block on a try-except.>>> import astroid >>> node = astroid.extract_node(''' try: do_something() except Exception as error: print("Error!") ''') >>> node <Try l.2 at 0x7f23b2e9d908> >>> node.handlers [<ExceptHandler l.4 at 0x7f23b2e9e860>]
- 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.