Code: Select all
f(){
try{
}finally{
return '2'
}
}
f()
Code: Select all
f(){
try{
}finally{
return '2'
}
}
f()
Exit can be used like Return in this case:Docs wrote:Goto, Break, Continue and Return cannot be used to exit a Finally block, as that would require suppressing any control flow statements within the Try block. For example, if Try uses return 42, the value 42 is returned after the Finally block executes. Attempts to jump out of a Finally block using one of these statements are detected as errors at load time where possible, or at run time otherwise.
Code: Select all
f(){
try{
if Mod(A_Min, 2)
throw Error("That's odd...")
}finally{
exit 2
}
}
f()
Wrong. C# does not - I would bet that the other .NET languages do not either.as every other language supports return in finally
Code: Select all
f() { ; Note this function returns 3.
try return 2
finally
return 3
}
Code: Select all
f() { ; Note this function returns 3.
try result := 2
finally
result := 3
return result
}
iseahound wrote: ↑20 Jul 2023, 07:24could be done via assignment:Code: Select all
f() { ; Note this function returns 3. try return 2 finally return 3 }
I'm having trouble understanding how much better it is to allow a return in a finally block, as I haven't seen any examples online in other languages where its usage is convincing.Code: Select all
f() { ; Note this function returns 3. try result := 2 finally result := 3 return result }