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.