`else` block in `try` statement swallows exceptions

オープン
#615 コメント 4 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript, python
領域
compilers

調査の方向性

No source file or test is named. Start by tracing how the compiler translates the provided Python try/except/else example, then verify that an exception raised in the else block reaches the outer context instead of being swallowed; issue #99 may provide related history.

索引モデルが issue の本文から書いたものです。

説明

STATE: under consideration

Exceptions raised in the else block should bubble out, but instead they currently get suppressed.

This:

try:
    pass
except:
    pass
else:
    raise Exception('something wrong happened in the `else`')

compiles to:

try {
        // pass;
        try {
                var __except0__ = Exception ('something wrong happened in the `else`');
                __except0__.__cause__ = null;
                throw __except0__;
        }
        catch (__except0__) {
        }
}
catch (__except0__) {
        // pass;
}

I suggest: set a temporary boolean variable to true before the try, then flip it to false as the very first statement inside the catch, and then have an if statement on that boolean as the very first statement after the catch block (it might be better to just always generate that if inside a finally in the JavaScript even if there is no finally in the Python, because it has to execute before any finally if it does exist).

(My reasoning for flipping the boolean as the first statement in the catch instead of the last statement in the try is that if for some reason ever a JavaScript implementation existed that raised an exception while trying to set that internal implementation book-keeping variable, I think it better that our generated code explode that up a level, instead of it being caught by the local except block, because logically that is an error within the try statement itself, not the block of code inside it.)

P.S. In similar situations in the future, would you prefer I reopened #99 instead of creating this new issue?

主要言語
Python
スター
2.9k
フォーク
218
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TranscryptOrg/Transcrypt のほかの issue

TranscryptOrg/Transcrypt の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。