If I have code like
try
{
return;
}
catch
{
return;
}
finally
{
return;
}
from which block will the value will be returned. and try
has been executed without any error.
Answers were Sorted based on User's Feedback
Answer / prajaktaa
In this scenario, the whole try block will get executed and
control will then be passed to finally block.
But an error come while executing finally block that Cannot
exit from finally block and execution gets stucks.
| Is This Answer Correct ? | 11 Yes | 1 No |
Answer / djay
//compile time error control can not leave the body of a finally block
| Is This Answer Correct ? | 8 Yes | 0 No |
Answer / jens
It won't; that construction isn't allowed. You can't have a
return in the finally clause. Once that is removed there is
no problem, right?
Try this, call it from some code that displays the result
and then uncomment the //for...-line and run again.
private int WeirdTry()
{
int foo = 10;
int result = 4;
try
{
//for (int i = 0; i < 100; i++) result = 1 /
(foo - i);
return result;
}
catch (Exception ex)
{
MessageBox.Show("Exception " +
ex.InnerException);
return result;
}
finally
{ MessageBox.Show("finally ");}
}
/Jens
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / vijay k chin
the above block will not execute as control will be unable to enter in to the filnally block. So return statement should be always in finally block not in the try block.
| Is This Answer Correct ? | 1 Yes | 5 No |
Which of these string definitions will prevent escaping on backslashes in c#?
What are the two kinds of properties?
Are all methods virtual in c#?
can we assign null value to value type in c#?
12 Answers Idea, Microsoft, Wipro,
Is everything an object c#?
Explain the difference between the debug class and trace class?
What is marker interface?
What?s the difference between an interface and abstract class?
Is c# easier than javascript?
How do you comment in c#?
What is the difference between read and readline in c#?
How to create multi-dimensional array?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)