[Pitch] Optional.orThrow

My favourite alternative of making a "crash safe version of !" (which is essentially what this pitch is about) is unchecked exceptions. Benefits:

  • as with x^ alternative mentioned above, it will support L-value expressions. This is in sharp contrast to anything discussed before in this of previous related pitches.

  • compared to x^ mentioned above will not require a language / compiler change (only the standard library change).

  • will require a minimal amount of source changes (textually it would still look like x! just behave slightly differently if embedded within dynamicTry/catch brackets directly or indirectly. Note that this is a strict opt-in (if you don't "activate" this feature by using dynamicTry/catch there won't be any behavioural changes).

  • could be used for other things later on (array subscripts, etc)

1 Like