If you use multithreading, I strongly recommend you **not** to use exceptions 
in your code.

Use `Option` or `Result[T, cstring]` from 
<https://github.com/status-im/nim-stew/blob/1db43c72/stew/results.nim> instead 
and ensure that no exceptions can happen or are all handled in the proc that 
will be distributed by tagging your proc with `{.raises: [].}` or only allow 
unrecoverable errors with``{.raises: [Defect].}``. You can use `{. push 
raises:[].}` to apply that to the whole file.

The reason why is that Nim exceptions are `ref object` and so involve the 
thread-local GC, which is ... thread-local. If your thread dies to an 
exception, the GC is also dead and so you are likely accessing undefined memory.

For the same reason, `Result[T, cstring]` is preferable to `Result[T, string]` 
as C-string will not involve a GC-managed type be shared across threads with 
the memory owner dying to an exceptions.

This might change with `--gc:arc` and/or in C++ mode if Nim exceptions uses C++ 
exceptions handling (without allocating for the message).

Reply via email to