elvish: `except` must be in the same line as `}`

This code is ok:

try { 
    
    fail bad 

} except e {            # <= ok!

    put $e 
}

But if you move except to the next line

try { 
    
    fail bad 
}
except e {              # <= here

    put $e 
}

you get this very misterious error:

# compilation error: variable $e not found
# /home/tfga/sbin/exceptBug.elv, line 11:     put $e

Would it be possible to lift this restriction?

In any case, the error message is very puzzling. It took me a long time to figured out what exactly I had done wrong.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 21 (14 by maintainers)

Most upvoted comments

@tfga I have to agree with others here. To be honest, this aspect of Elvish also bit me a few times at the beginning, but you get used to it and live with it. It’s no different than syntax peculiarities or requirements in any other language.

In any case, personally I think that

if whatever {
   foo
} else {
  bar
}

is clearer and more readable than

if whatever { foo }
else { bar }

despite it being more compact.