Hi, I'm having trouble using custom exceptions; any clue what I'm doing wrong
here:
mymodule.nim:
type myModuleException* = ref object of Exception
extraData : uint32
proc myModuleFunc*() =
var ex : myModuleException
new(ex)
ex.extraData = 12
raise ex
Run
main.nim:
import mymodule
try:
mymoduleFunc()
except myModuleException as ex:
echo ex.extraData
Run
When compiling (with nim 1.0.4) I get:
user@host:~/temp/nimExceptions$ nim c -r main.nim
Hint: used config file
'/home/user/.choosenim/toolchains/nim-1.0.4/config/nim.cfg' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: main [Processing]
Hint: mymodule [Processing]
/home/user/temp/nimExceptions/main.nim(7, 10) Error: undeclared field:
'extraData'
Run
Nim version:
user@host:~/temp/nimExceptions$ nim -v
Nim Compiler Version 1.0.4 [Linux: amd64]
Compiled at 2019-11-27
Copyright (c) 2006-2019 by Andreas Rumpf
git hash: c8998c498f5e2a0874846eb31309e1d1630faca6
active boot switches: -d:release
Run