(language) Add support for returning errors

Errors can now be returned from methods returning a union type (a new concept introduced in this change) where one of the types listed is error, e.g. bool | error. An initial ArgumentError class is also introduced.

For now, errors cannot be handled on the calling side, but a new keyword try has been added. This keyword means "propagate the error onwards". The top-level main method will then print an "Unhandled error" message and some details from the error (including a slightly primitive stack trace).

The intent here is to try and strike a balance between languages like Java (which is exception-based, making it easy to propagate exceptions onwards) and languages like C/Go/Rust, where errors are typically handled closer to the method generating them. So, something like: "more explicit than Java" and "less verbose than Go".

Edited by Per Lundberg

Merge request reports

Loading
Loading