Handling exceptions occurred in catch block


Exceptions are handled by try catch finally

Description



Handling exceptions occurred in catch block

try
{
func1();

}
catch (Exception exfinal)
{
label1.Text = exfinal.Message + exfinal.Source + exfinal.InnerException.Message;

}
public void func1()
{
try
{


Exception ex = new Exception("MAIN EXCEPTION");
throw ex;
}
catch (Exception ex)
{
try
{
Exception ex1 = new Exception("from next ", ex);

}
catch (Exception ex1)
{
throw ex1;
}

}


}



Explanation:
Generally the exceptions r handled by try…catch…finally. The above snippet demonstrates how to handle exception in catch block using try …catch. The exceptions flow from parent exception to child exception and the respective exception is catched according to situation.


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: