Can we keep multiple catch block in C# ?


Yes. We can keep the multiple catch block in C#. A try block can throw the multiple exceptions,which can be handle by using multiple catch block. We can use in this scenario

protected void BtnSubmit_Click(object sender, EventArgs e)
{
int x = 0;
int div = 0;

try
{
div = 100 / x;
Response.Write("Not excecuted line");
}
catch (DivideByZeroException de)
{
Response.Write("Divide of Zero exception");
}
catch (Exception ee)
{
Response.Write("Exception");
}
finally
{
Response.Write(" Finally block executed");
}

}

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.