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



If I have code like try { return; } catch { return; } finally { return; } fro..

Answer / claivan

Finally block will not return any values as it gives
error "Control cannot leave the body of a finally clause".
The finally block is useful for cleaning up any resources
allocated in the try block.

Is This Answer Correct ?    13 Yes 0 No

If I have code like try { return; } catch { return; } finally { return; } fro..

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

If I have code like try { return; } catch { return; } finally { return; } fro..

Answer / djay

//compile time error control can not leave the body of a finally block

Is This Answer Correct ?    8 Yes 0 No

If I have code like try { return; } catch { return; } finally { return; } fro..

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

If I have code like try { return; } catch { return; } finally { return; } fro..

Answer / vadivel

finally

Is This Answer Correct ?    0 Yes 1 No

If I have code like try { return; } catch { return; } finally { return; } fro..

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

Post New Answer

More C Sharp Interview Questions

What?s an abstract clas?

5 Answers   Mind Tree,


What is polymorphism? pl explain practically rather than theoretical?

3 Answers  


What is literal in c#?

0 Answers  


What is wpf application in c#?

0 Answers  


Okay, so an int is a value type, and a class is a reference type. How can int be derived from object?

0 Answers  






Explain the difference between passing parameters by value and passing parameters by reference with an example?

0 Answers  


Can I use parseint?

0 Answers  


What is the use of ispostback in c#?

0 Answers  


what is the default access for a class

0 Answers   Cognizant,


What is difference between array and list?

0 Answers  


What Is A Satellite Assembly?

0 Answers   PUCIT, Siebel Systems,


if a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can you enforce a call from an inherited constructor to a specific base constructor?

0 Answers   Siebel Systems,


Categories