Skip to content

Makes except: panics on Defect #24821

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Apr 3, 2025
Merged

Makes except: panics on Defect #24821

merged 14 commits into from
Apr 3, 2025

Conversation

ringabout
Copy link
Member

@ringabout ringabout commented Mar 28, 2025

implements nim-lang/RFCs#557

It inserts defect handing into a bare except branch

try:
  raiseAssert "test"
except:
  echo "nope"

=>

try:
  raiseAssert "test"
except:
  # New behaviov, now well-defined: **never** catches the assert, regardless of panic mode
  raiseDefect()
  echo "nope"

In this way, except still catches foreign exceptions, but panics on Defect. Probably when Nim has except {.foreign.}, we can extend raiseDefect to foreign exceptions as well. That's supposed to be a small use case anyway.

--legacy:noPanicOnExcept is provided for a transition period.

@Araq Araq merged commit 26b86c8 into devel Apr 3, 2025
21 checks passed
@Araq Araq deleted the pr_transform_bare_except branch April 3, 2025 14:10
Copy link
Contributor

github-actions bot commented Apr 3, 2025

Thanks for your hard work on this PR!
The lines below are statistics of the Nim compiler built from 26b86c8

Hint: mm: orc; opt: speed; options: -d:release
179130 lines; 8.632s; 651.891MiB peakmem

narimiran pushed a commit that referenced this pull request Apr 4, 2025
implements nim-lang/RFCs#557

It inserts defect handing into a bare except branch

```nim
try:
  raiseAssert "test"
except:
  echo "nope"
```

=>

```nim
try:
  raiseAssert "test"
except:
  # New behaviov, now well-defined: **never** catches the assert, regardless of panic mode
  raiseDefect()
  echo "nope"
```

In this way, `except` still catches foreign exceptions, but panics on
`Defect`. Probably when Nim has `except {.foreign.}`, we can extend
`raiseDefect` to foreign exceptions as well. That's supposed to be a
small use case anyway.

 `--legacy:noPanicOnExcept` is provided for a transition period.

(cherry picked from commit 26b86c8)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants