Back to questions
JuniorTheoryCommon
What does the program print?
Console.WriteLine(Get());
int Get()
{
try
{
return 1;
}
finally
{
Console.Write("B");
}
}B1
- Expecting
1B:finallyruns whileGetis still leaving, before the caller gets the value, soBis written first. - Expecting
returnto leave at once and skipfinally:finallyruns on every way out oftry.
- What changes in the output if
trythrows an exception that the caller catches, instead of returning? - Why can't the
finallyblock hold areturnof its own?