M
Modular2y ago
Igor

Raise returns a string?

I'm running this code:
fn test() raises -> StringRef:
raise Error("Test")


fn main() raises:
let res = test()

print(res) # prints "Test"
fn test() raises -> StringRef:
raise Error("Test")


fn main() raises:
let res = test()

print(res) # prints "Test"
It seems like if I raise an error on a function that returns a String then the error value becomes the return value... Is that expected behavior?
3 Replies
Michael K
Michael K2y ago
You should filed a bug report (https://github.com/modularml/mojo/issues). The behavious seems specific to raising in a fn that returns a StringRef. Other return types raise appropriately and the print statement is never reached.
Igor
IgorOP2y ago
GitHub
[BUG]: raises returns a StringRef · Issue #926 · modularml/mojo
Bug description When you have a function that returns a StringRef and it raises an error the function will return the value of that error. Is this expected behavior? Steps to reproduce fn test() ra...
Jack Clayton
Jack Clayton2y ago
Thanks very much for the report this is currently being worked on

Did you find this page helpful?