mojo
mojo copied to clipboard
[Docs] Add Error Handling example in HelloMojo Notebook
Where is the problem?
HelloMojo,ipynb
What can we do better?
There isn't much explanation about the Error Handling portion.
Both [def and fn] support raising exceptions, but this must be explicitly declared on a fn with the raises function effect, placed after the function argument list.
I think it would be helpful to add something like the simple example below for reference:
fn raise_an_error(num: Int) raises -> Int:
if num < 0:
raise Error("I'm an error!")
return num + 1
try:
print(raise_an_error(-1))
except:
print("exception")
Anything else?
No response
Thanks for this suggestion! There are definitely some basic language features not documented yet, but these sort of things should typically work the same as in Python, so they have been lower on our documentation priorities. We'll get to it soon, though. Thanks again.
@scottamain any status update on this?
Sorry, other priorities continue to keep this one low. I believe all error handling in Mojo is the same as Python's, right @Mogball?
Yes. It's the same. If you are not actively working on it, please unassign yourself