mojo icon indicating copy to clipboard operation
mojo copied to clipboard

[Docs] Add Error Handling example in HelloMojo Notebook

Open maevadevs opened this issue 1 year ago • 4 comments

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

maevadevs avatar May 27 '23 03:05 maevadevs

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 avatar May 30 '23 19:05 scottamain

@scottamain any status update on this?

Mogball avatar Jul 17 '23 18:07 Mogball

Sorry, other priorities continue to keep this one low. I believe all error handling in Mojo is the same as Python's, right @Mogball?

scottamain avatar Jul 17 '23 20:07 scottamain

Yes. It's the same. If you are not actively working on it, please unassign yourself

Mogball avatar Jul 17 '23 20:07 Mogball