I came across an unintuitive behavior when writing a macro, where a 
JsonParsingError thrown by `marshal.to` was not catchable, even though it was 
placed in a try...except block.

Code
    
    
    import marshal
    
    macro caught() =
        try:
            raise newException(Exception, "blah")
        except:
            echo "oops"
    
    macro uncatchable() =
        try:
            let x = to[seq[string]]("yadayada")
            discard x
        except:
            echo "oops"
    
    # oops
    caught()
    
    # parsejson.nim(515)       raiseParseErr
    # Error: unhandled exception: unknown file(1, 8) Error: '[' expected for a 
seq expected [JsonParsingError]
    uncatchable()
    
    
    
    
    Run

nim -v Nim Compiler Version 1.6.8 [Linux: amd64] Compiled at 2022-10-05 
Copyright (c) 2006-2021 by Andreas Rumpf git hash: 
c9f46ca8c9eeca8b5f68591b1abe14b962f80a4c active boot switches: -d:release

Compile with `nim c` to get the output.

The JsonParseError seems to be defined 
[here](https://github.com/nim-lang/Nim/blob/v1.6.8/lib/pure/parsejson.nim#L76) 
which is a ValueError, so I'd expect it to be catchable. 

Reply via email to