can we nested try catch block

Posted by Jameschowdare under C# on 12/3/2009 | Views : 3961 | Status : [Member] | Replies : 5
explain us

the order of nested try cath block,




Responses

Posted by: Vuyiswamb on: 12/4/2009 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
lets say i want to connect to the Database

Try 

{
con.Open();
}
catch(SQlException ex) //if there is an Error Catch it here
{
Label1.Text = ex.Message; //Display your Error in the Message

}
Finally //Finnaly dispose all the objects and Close the Connection
{
if (con != null)
{
con.Close();
}
}


Thank you for posting at Dotnetfunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Jameschowdare, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Muhilan on: 12/4/2009 [Member] Starter

Up
0
Down
yes we can nested try catch block

ex..


try

{
try
{
DoEverything();
}
catch (Exception ex)
{

}
}
catch (Exception ex)
{

}




Jameschowdare, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jameschowdare on: 12/4/2009 [Member] Starter

Up
0
Down
explain me how the order of the execution

Jameschowdare, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Virendradugar on: 12/4/2009 [Member] [MVP] Silver

Up
0
Down
If the inner try block throws the exception and it will be catch by the inner catch only.



Jameschowdare, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jameschowdare on: 12/24/2009 [Member] Starter

Up
0
Down
here both try blocks will work ?

Jameschowdare, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response