Is it possible to catch a compiler parse error in a test suite?

For instance, if I overload a template for the + operator for int and string 
but not for a mix of these types, and I would like to detect that code that 
does not respect this constraint is detected by my program to print an error 
message in place of the error from the compiler.
    
    
    import unittest
    
    template `+`*(a, b: int): int = ...
    
    template `+`*(a, b: string): string = ...
    
    suite "base types":
      test "bad syntax":
        # Mixing int and string is not allowed: should throw an error to the 
user
        expect CompilerParseError:    <== How do I detect it?
          let z = 3 + "foo"
    
    
    Run

In fact, in this small example, as the + parameter types are limited in number, 
I could define myself the catch-all template that throw the exception
    
    
    template `+`*[T, T1, T2](a: T1, b: T2): T =
      raise newException(CompilerError, "You can't mix types in `+` operation")
    
    
    Run

but my code is more complex and such a solution is not viable.

So is there a way to detect that an error happened at compiler parsing phase 
and catch it?

Reply via email to