`else` block in `try` statement swallows exceptions

Đang mở
#615 4 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript, python
Lĩnh vực
compilers

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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?

Ngôn ngữ chính
Python
Star
2.9k
Fork
218
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của TranscryptOrg/Transcrypt

Tất cả issue của TranscryptOrg/Transcrypt

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.