Skip to content

[FEATURE] Rust-like or Java-like Error handling from function return #1209

@vladceresna

Description

@vladceresna

Now, as I understood from documentation on wren.io, we don't know what we will get from the function - which type, class, object, or just our program will be shutting down because we have error in some place in function.

So, we need to have normal error handling features. And I have 2 thoughts about how we can implement it in Wren.

  1. Rust-like - Results with Errors and unwrap()
ourFunction(input) -> Result<String, Error> {
    return Ok("") // or return Err("Message")
}
System.print(ourFunction("").unwrap())
match ourFunction("") {
    Ok(v) -> System.print(v),
    Err(e) -> System.print(e)
}

This way needs Enums to be implemented already.

  1. Java-like - Exceptions and try/catch
ourFunction(input) throws Exception -> String {
    return "" // or throw Exception("")
}
try {
    ourFunction("")
} catch(e) {
    System.print(e)
}

So, I prefer Rust-like style, but I think, we need more thoughts from other developers for understand, what actually is really to implement in small Wren nature and which syntax is better to use in this cases.

Also, I think, good point is to have ability to mention type of value, which we return from function or get in function. Because it will rank up safety and, perspectively, performance of code, written in Wren.

Thanks for your work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions