While implementing a macro I wanted to play nice for the user and show lineinfo() in case of parsing error, since parseExpr was pointing to the line of the macro rather than the callsite line. I wrapped parseExpr in a try/except but when I removed the failing code the except was still being run. See this example too:
import macros
macro rambo(text: string): expr =
result = newLit("'" & text.strVal & "'")
macro ghost(text: string): expr =
try:
result = newLit("ok ")
except:
result = newLit("wat ")
const
a = "something "
b = ghost("ghostly ")
c = rambo("stallone")
echo a, b, c
This example produces something wat 'stallone' when run instead of the expected something ok 'stallone'. If exceptions don't work at compile time, how can one catch user mistakes in parseExpr and the like?