Zulip Chat Archive
Stream: lean4
Topic: Nested try catch
Patrick Massot (Feb 11 2026 at 09:23):
Could we have a better error message in
import Lean
elab "foo" : tactic => do
try
evalTactic (← `(tactic|skip))
try
evalTactic (← `(tactic|skip))
catch _ =>
throwError "One"
catch _ => do
throwError "Two"
Patrick Massot (Feb 11 2026 at 09:25):
Here Lean complains on the first try that invalid `try`, it must have a `catch` or `finally` , which seems pretty unfair to me.
Patrick Massot (Feb 11 2026 at 09:25):
To be honest I don’t even understand why this is incorrect code.
Sebastian Ullrich (Feb 11 2026 at 10:21):
It's likely associating both catch to the first try, that would be a parser bug
Yaël Dillies (Feb 11 2026 at 10:27):
I encountered this recently too. I had to resort to doing try { try ... catch ... } catch .... I agree it is annoying.
Robin Arnez (Feb 11 2026 at 11:15):
This is lean4#8220. I have a fix but it's unfortunately a bit more complicated than I would've hoped it to be. And for anyone wondering, the complicated cases are:
if ... then
...
else try
...
catch _ =>
...
and
let _ ← try
...
catch _ =>
...
Patrick Massot (Feb 11 2026 at 16:11):
Thanks! Yaël, could you please upvote that bug report?
Last updated: Feb 28 2026 at 14:05 UTC