mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-13 06:43:52 +00:00
implements https://github.com/nim-lang/RFCs/issues/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.
23 lines
427 B
Nim
23 lines
427 B
Nim
discard """
|
|
matrix: "--legacy:noPanicOnExcept"
|
|
"""
|
|
|
|
import options
|
|
type Foo = ref object
|
|
i: int
|
|
|
|
proc next(foo: Foo): Option[Foo] =
|
|
try: doAssert(foo.i == 0)
|
|
except: return # 2º: none
|
|
return some(foo) # 1º: some
|
|
|
|
proc test =
|
|
let foo = Foo()
|
|
var opt = next(foo) # 1º Some
|
|
while isSome(opt) and foo.i < 10:
|
|
inc(foo.i)
|
|
opt = next(foo) # 2º None
|
|
doAssert foo.i == 1, $foo.i
|
|
|
|
test()
|