# Why can't a failure context have an else clause?

**URL:** <https://forums.unrealengine.com/t/why-cant-a-failure-context-have-an-else-clause/2066861>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [October 13, 2024, 7:00pm UTC](https://forums.unrealengine.com/t/why-cant-a-failure-context-have-an-else-clause/2066861 "2024-10-13T19:00:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mobifruit](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mobifruit/32/985104_2.png) [@mobifruit](https://forums.unrealengine.com/u/mobifruit)\
**Post date:** [October 13, 2024, 7:00pm UTC](https://forums.unrealengine.com/t/why-cant-a-failure-context-have-an-else-clause/2066861/1 "2024-10-13T19:00:45Z")

</div>

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**?

```auto
        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:

```auto
        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?

---

<div class="post-metadata">

**Author:** ![im\_a\_lama](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/im_a_lama/32/995063_2.png) [@im\_a\_lama](https://forums.unrealengine.com/u/im_a_lama)\
**Post date:** [October 14, 2024, 8:02am UTC](https://forums.unrealengine.com/t/why-cant-a-failure-context-have-an-else-clause/2066861/2 "2024-10-14T08:02:08Z")

</div>

> [@mobifruit](#):
>
> The Verse compiler would complain that _DistanceBetweenPositions_ is an “Unknown identifier” as it is not in scope.

I’m pretty sure Verse uses [short circuit evaluation](https://en.wikipedia.org/wiki/Short-circuit_evaluation) which means that if your `if` condition fails on the first statement (AllPlayers[0], i.e. the AllPlayers array is empty), then it will not try to solve the other conditions, including `DistanceBetweenPositions: float = DistanceXY(FirstPosition.Translation, SecondPosition.Translation)`, which is why you can’t access this variable

If you want to keep access to this distance variable you would write your condition as such :

```auto
if:
    Player:player = AllPlayers[0]
    FortniteCharacter:fort_character = Player.GetFortCharacter[]
    set SecondPosition = FortniteCharacter.GetTransform()
    DistanceBetweenPositions: float = DistanceXY(FirstPosition.Translation, SecondPosition.Translation)
then:
            
    if(DistanceBetweenPositions < 1000.0):
        Print("Distance Moved: {DistanceBetweenPositions}")
        Print("Applying Damage")
        HurtPlayer(50.0)
    else:
        Print("Distance Moved: {DistanceBetweenPositions}")
        Print("Nobody got hurt ;-)")

```
