Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

How can I handle multi type error?

SQL + custom or other ones?

 

catch (SqlException e01)

{

//Response.Write(e01.Number.ToString());

if (e01.Number == 2601)

{

Label4.Text ="Error msg";

}

else

 

Label1.Text = e01.Message.ToString();

 

}

  • Administrators
Posted (edited)

You could use a switch statement within the SQLException handler to decide based on the SQL error number and also have multiple Exception handlers to handle other (non-SQL) exceptions

i.e.

try
      {
      }
catch (SqlException e01)
{
//Response.Write(e01.Number.ToString());
switch (e01.Number)
       	{
	case  2601:
		{
		Label4.Text ="Error msg";
		}
	case 50001:
		{
		//etc
		}
	default:
		{
		Label1.Text = e01.Message.ToString();
		}
	}
}
catch (ArithmeticException ex)	//and so on
{

}

Edited by PlausiblyDamp

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...