Open f-saez opened 3 weeks ago
Confirming that this is a change in behavior since 24.4. To me this seems like a correct change to require that there is an except statement or that the function raises here but the error message doesn't look quite right. @Mogball for his view on this as well and what this needs.
This is correct behaviour. We should improve the error message here, since it can be confusing. The try block needs an except region since the surrounding context is not raising.
@Mogball What about requiring raises if there is no except clause? As of python 3.12 the following raises no syntax errors (even when you replace the raise with a pass) but has simply has no error handling:
try:
raise Exception()
finally:
pass
@Mogball What about requiring raises if there is no except clause? As of python 3.12 the following raises no syntax errors (even when you replace the raise with a pass) but has simply has no error handling:
try: raise Exception() finally: pass
In Python, this is equivalent to writing
try:
raise Exception()
except:
raise
finally:
pass
I.e., the errors are passthrough the try-finally clause. In Mojo, the behaviour is the same.
def try_finally():
try:
raise "whoops"
finally:
pass
The problem in the example reported in the issue is that the try-finally
clause itself is not in a context that can raise, thus it cannot implicitly re-raise. We should improve the error message here to be more specific!
Makes sense, thanks for clarifying :)
Bug description
Hi,
I've noticed a strange behavior with the last nightly.
it doesn't compile, with the following error message :
If I change finally by except
everything's fine again.
Steps to reproduce
run the small piece of code
System information