Closed ITwrx closed 10 months ago
handleGet()
can call procs that may raise exceptions, but you need to handle them with the try statement. Basically like this:
proc handleGet() {.gcsafe, raises: [].} =
try:
let html = bkTestTemplate()
reply(html)
except: reply(Http500)
Wow, i can't believe i never thought to try that, although i think the nim docs could be more explicit that the try
is mandatory for compilation in this situation. I guess i thought you only needed try
when you wanted to catch and handle specific exceptions. It compiles without any {.raises.}
pragmas now. Thanks for the help!
Hi, I think my
type mismatch
problem in #14 was actually due to exception handling and not necessarily gcsafe (yet?). The GuildenStern httpserver request callback specifies {.raises: [].}, but the GuildenStern README example does not. I guess I can useproc handleGet() =
only if there are no possible exceptions in any procs that are called during that request handling? I haven't had to deal with these exception pragma notations before with any other server/framework, so i've been trying to brush up on it, but i'm not having much luck getting it to compile. The compiler keeps complaining about different procs and their possible exceptions. Below is an example of my testing code with current exception appeasement attempt. :) I'm just trying to perform one sql statement with sqliteral and output in a nim SCF template to see how it's all supposed to work together.main_gs.nim
gs_test.nimf
CatachableError below was just a catchall attempt to try to get it to compile. It was complaining about SQLError:ObjectType, but i wasn't sure how to specify that.
sql_ss_model.nim
i'm not sure about the last few lines of sql_ss_model.nim. All the sqliteral examples use prepareStatements() instead of prepareSql(), and i haven't got to test it yet due to the exceptions issues.
Thanks! I'm hoping if i can get my little test working i won't have to bother you so much. :)