Kipper icon indicating copy to clipboard operation
Kipper copied to clipboard

[Feature] Implement try/catch statement to handle exceptions

Open lorenzholzbauer 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

Add try/catch statement support, which can handle exceptions and execute specific clauses based on error pattern matching. It also includes a finally clause, which gets executed regardless of what happened before.

var x: num;
try {
  x = fetch("http://localhost") force as num;
} catch (e: InvalidCastException) {
  x = 2;
} finally {
  print(x as str):
}

Exact behaviour / changes you want

  • [ ] Add try/catch notation and appropriate semantic analysis.
  • [ ] Add translation to JavaScript and TypeScript.

lorenzholzbauer avatar Jul 09 '24 11:07 lorenzholzbauer