modularml / mojo

The Mojo Programming Language
https://docs.modular.com/mojo/manual/
Other
22.87k stars 2.58k forks source link

[Docs] Add Error Handling example in HelloMojo Notebook #269

Open maevadevs opened 1 year ago

maevadevs commented 1 year ago

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

scottamain commented 1 year ago

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.

Mogball commented 1 year ago

@scottamain any status update on this?

scottamain commented 1 year ago

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

Mogball commented 1 year ago

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