def node_try_stmt(self, node):
        jsvars = self.jsvars.copy()
        childs = node.children.__iter__()
        # syntax ensures fixed order
        # try:
        # except-clauses:
        # except:
        # else:
        # finally
        self.assert_value(node, childs.next().value, 'try')
        self.assert_value(node, childs.next().value, ':')
        _try = childs.next()
        _except_clauses = []
        _except = None
        _else = None
        _finally = None
        try:
            while True:
                child = childs.next()
                if isinstance(child, Leaf):
                    if child.value == 'except':
                        self.assert_value(node, childs.next().value, ':')
                        _except = childs.next()
                    elif child.value == 'else':
                        self.assert_value(node, childs.next().value, ':')
                        _else = childs.next()
                    elif child.value == 'finally':
                        self.assert_value(node, childs.next().value, ':')
                        _finally = childs.next()
                    else:
                        raise NotImplementedError(repr(node))
                elif type_repr(child.type) == 'except_clause':
                    self.assert_value(node, childs.next().value, ':')
                    _except_clauses.append((child, childs.next()))
                else:
                    raise NotImplementedError(repr(node))
        except StopIteration:
            pass
        track_len = self.get_tmp_jsname('track$len')
        self.add_lines("var %s = $pyjs.trackstack.length;" % track_len)
        self.add_lines("try {", node.children[0].lineno)
        self.indent()
        self.dispatch(_try)
        if _else is not None:
            self.add_lines("throw %(try_else)s" % jsvars)
        self.dedent()
        self.add_lines("} catch (%(catch)s) {" % jsvars)
        self.indent()
        self.add_lines("var %(catchclass)s = %(catch)s['__class__'];" % jsvars)
        self.add_lines(
            "$pyjs.trackstack.splice(%s, $pyjs.trackstack.length);" % (
                track_len,
            ),
        )
        elseif = "if"
        jsvars.update(locals())
        if _else is not None:
            self.add_lines("if (%(catchclass)s === %(try_else)s['__class__']) {" % jsvars)
            self.indent()
            self.dispatch(_else)
            self.dedent()
            elseif = "} else if"
        for clause, suite in _except_clauses:
            # See node_except_clause
            classes, varname = self.dispatch(clause)
            jsvars['classes'] = ', '.join([str(i) for i in classes])
            jsvars['elseif'] = elseif
            self.add_lines("""%(elseif)s(%(builtin)s['_issubclass'](%(catchclass)s, [%(classes)s])) {""" % jsvars)
            self.indent()
            if varname:
                self.add_lines("%s = %s;" % (varname, jsvars['catch']))
            self.dispatch(suite)
            self.dedent()
            elseif = "} else if"
        if elseif != "if":
            self.add_lines("} else {")
            self.indent()
        if _except is None:
            self.add_lines("throw %(catch)s;" % jsvars)
        else:
            self.dispatch(_except)
        if elseif != "if":
            self.dedent()
            self.add_lines("}")
        if _finally is not None:
            self.dedent()
            self.add_lines("} finally {")
            self.indent()
            self.dispatch(_finally)
        self.dedent()
        self.add_lines("}")
dataset/ETHPy150Open anandology/pyjamas/pyjs/src/pyjs/translator_dict.py/Translator.node_try_stmt/original