While experimenting with Lesson 9 of “Learn the Basics of Writing Code in Verse” the following got me wondering: Why isn’t it possible in Verse to write an else clause for a so-called failure context?
if:
Player:player = AllPlayers[0]
FortniteCharacter:fort_character = Player.GetFortCharacter[]
set SecondPosition = FortniteCharacter.GetTransform()
DistanceBetweenPositions: float = DistanceXY(FirstPosition.Translation, SecondPosition.Translation)
DistanceBetweenPositions < 1000.0
then:
Print("Distance Moved: {DistanceBetweenPositions}")
Print("Applying Damage")
HurtPlayer(50.0)
In contrast to common if-then-else constructions with Boolean (logic) in parenthesis as ConditionFunction[.]. This might not be particularly jarring, but could IMHO be convenient if you would like the simply handle the otherwise case like:
else:
Print("Distance Moved: {DistanceBetweenPositions}")
Print("Nobody got hurt ;-)")
The Verse compiler would complain that DistanceBetweenPositions is an “Unknown identifier” as it is not in scope.
Why this limitation of the Verse grammar regarding failure contexts? Any particular reason? Or is it simply by design of the language that there is not support for an explicit success code path?
PS. How does it compare to Java’s try {} catch {} finally {} construct?