Hello everyone,
I am trying to wrap the raise operator in a procedure like so:
proc raiseException* [E: CatchableError](e: ref E; R: typedesc): R {.raises: [E].} =
raise e
when isMainModule:
try:
newException(IOError, "").raiseException(void)
except IOError:
echo "exception caught"
I tried to compile that program with Nim 0.20.2 and I had the following error:
prog.nim(1, 79) Error: invalid type for raises/tags list
I think the compiler verifies what raiseException can raise before the procedure can be used, but I could be wrong.
So, is what I am trying to do possible ? And if yes, how ?
From what I understood, the E inside the pragma is not instantiated. Not sure if it's a bug or intentional design.
For now just drop the {.raises.} annotation, the compiler can compute this on its own.
Thanks for the reply.
For now just drop the {.raises.} annotation, the compiler can compute this on its own.
Yes, it works indeed, thanks a lot.
I originally intended to make a lazy version of raiseException like this:
import std/sugar
proc raiseException* [E: CatchableError](e: () -> ref E; R: typedesc): (proc (): R {.raises: [E].}) =
() => raise e()
But then I ran into the same problem.
It is OK though, I can work around it.