Click here to Skip to main content
16,017,857 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using catch block with SqlException, but I want to show custom messages rather than exception itself. So how do I filter out the messages. Like say I want to catch a Unique Key Constraint Violation. Is there some error code which i can use to determine the error.
C#
protected void Button1_Click(object sender, EventArgs e)
       {
           try
           {

               objuser.username = txt_email.Text;
               objuser.email = txt_username.Text;
               objuser.password = txt_password.Text;
               int i = BusinessUser.BusinessRegisterUser(objuser);
               if (i > 0)
               {
                   Session["user_authenticate"] = "Verified";
                   Session["user_email"] = objuser.email; //  sql exception handle for uniqe key
                   Response.Redirect("user_registration.aspx");
               }
           }
           catch (SqlException ex)
           {
             // Handle Exception here if e-mail already exists
           }
           catch (Exception ex)
           {

           }

       }
Posted
Updated 21-Oct-13 0:59am
v2

 
Share this answer
 
Get the Inner Exception or read the exception message to understand the error. In order to provide the custom exception you have to write code to handle that in your catch block. There are no error codes associated with these errors.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900