Kipper icon indicating copy to clipboard operation
Kipper copied to clipboard

[Feature] Implement `throw` keyword to raise errors inside any code block

Open Luna-Klatzer opened this issue 7 months ago • 0 comments

Is there an existing proposal for this?

  • [X] I have searched the existing issues

This feature does not exist in the latest version

  • [X] I am using the latest version

Proposal

Implement throw keyword which should allow throwing any object of type Error.

For example:

throw new Error("An unexpected Error occurred");

The thrown error should then be catchable using the try/except statement as mentioned in #654:

try {
  ...
  throw new Error();
} except (e: Error) {
  print(f"Something happened! Cause: {e}");
}

Exact behaviour / changes you want

  • Implement new keyword and operator throw.
  • Add semantic checks and ensure that the thrown expression is always of type Error.
  • Add target code generation for JavaScript and TypeScript.

Luna-Klatzer avatar Jul 25 '24 08:07 Luna-Klatzer