shahab Posted June 15, 2004 Posted June 15, 2004 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(); } Quote
Administrators PlausiblyDamp Posted June 15, 2004 Administrators Posted June 15, 2004 (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 March 30, 2007 by PlausiblyDamp Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.