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 an except 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, None, None]#

Returns the assigned statement (non inferred) according to the assignment type. See astroid/protocols.py for actual implementation.

property blockstart_tolineno#

The line on which the beginning of this block ends.

Type:

int

body: list[NodeNG]#

The contents of the block.

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.

get_children()[source]#

Get the child nodes below this node.

name: AssignName | None#

The name that the caught exception is assigned to.

postinit(type: NodeNG | None, name: AssignName | None, body: list[NodeNG]) None[source]#
type: NodeNG | None#

The types that the block handles.