Skip to content

Commit 1df4deb

Browse files
ringaboutnarimiran
authored andcommitted
fixes bugs on the Nim manual (nim-lang#24669)
ref https://en.cppreference.com/w/cpp/error/exception/what > Pointer to a null-terminated string with explanatory information. The pointer is guaranteed to be valid at least until the exception object from which it is obtained is destroyed, or until a non-const member function on the exception object is called. The pointer is only valid before `CStdException as e` is destroyed Old examples are broken on macOS arm64 ``` /Users/blue/Desktop/nimony/test4.nim(38) test4 /Users/blue/Desktop/nimony/test4.nim(26) fn /Users/blue/.choosenim/toolchains/nim-#devel/lib/std/assertions.nim(41) failedAssertImpl /Users/blue/.choosenim/toolchains/nim-#devel/lib/std/assertions.nim(36) raiseAssert /Users/blue/.choosenim/toolchains/nim-#devel/lib/system/fatal.nim(53) sysFatal Error: unhandled exception: /Users/blue/Desktop/nimony/test4.nim(26, 3) `$b == "foo2"` [AssertionDefect] ``` (cherry picked from commit e6f6c36)
1 parent 1ff69ea commit 1df4deb

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

doc/manual.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5096,22 +5096,22 @@ caught by reference. Example:
50965096
proc fn() =
50975097
let a = initRuntimeError("foo")
50985098
doAssert $a.what == "foo"
5099-
var b: cstring
5099+
var b = ""
51005100
try: raise initRuntimeError("foo2")
51015101
except CStdException as e:
51025102
doAssert e is CStdException
5103-
b = e.what()
5104-
doAssert $b == "foo2"
5103+
b = $e.what()
5104+
doAssert b == "foo2"
51055105
51065106
try: raise initStdException()
51075107
except CStdException: discard
51085108
51095109
try: raise initRuntimeError("foo3")
51105110
except CRuntimeError as e:
5111-
b = e.what()
5111+
b = $e.what()
51125112
except CStdException:
51135113
doAssert false
5114-
doAssert $b == "foo3"
5114+
doAssert b == "foo3"
51155115
51165116
fn()
51175117
```

tests/cpp/tmanual_exception.nim

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
discard """
2-
# doesn't work on macos 13 seemingly due to libc++ linking issue https://stackoverflow.com/a/77375947
3-
disabled: osx
42
targets: cpp
53
"""
64

@@ -18,21 +16,21 @@ proc initStdException(): CStdException {.importcpp: "std::exception()", construc
1816
proc fn() =
1917
let a = initRuntimeError("foo")
2018
doAssert $a.what == "foo"
21-
var b: cstring
19+
var b = ""
2220
try: raise initRuntimeError("foo2")
2321
except CStdException as e:
2422
doAssert e is CStdException
25-
b = e.what()
26-
doAssert $b == "foo2"
23+
b = $e.what()
24+
doAssert b == "foo2"
2725

2826
try: raise initStdException()
2927
except CStdException: discard
3028

3129
try: raise initRuntimeError("foo3")
3230
except CRuntimeError as e:
33-
b = e.what()
31+
b = $e.what()
3432
except CStdException:
3533
doAssert false
36-
doAssert $b == "foo3"
34+
doAssert b == "foo3"
3735

3836
fn()

0 commit comments

Comments
 (0)