raviprakashg Posted May 2, 2007 Share Posted May 2, 2007 dear friends,how can i find the primary key or unique exception in catch block of my C# code, i am using SQL server 2000 for databasethanksraviprakashg Link to comment Share on other sites More sharing options...
jesh Posted May 2, 2007 Share Posted May 2, 2007 I'm not really sure what you're looking for here, posting your code may help.If you are trying to determine what type of Exception was thrown, this may help: try{ // some exception thrown here...}catch(Exception e){ Type exceptionType = e.GetType(); if (exceptionType == typeof(SqlException)) { // A SqlException was thrown } else if (exceptionType == typeof(IOException)) { // An IOException was thrown. } throw;} Otherwise, you can figure out what Exceptions may be thrown by your code and then catching them explicitly: try{ // some exception thrown here...}catch(SqlException sqe){ // A SqlException was thrown.}catch(IOException ioe){ // An IOException was thrown.}catch(Exception e){ // Either a generic Exception, or some other type of Exception was thrown.} Link to comment Share on other sites More sharing options...
raviprakashg Posted May 4, 2007 Author Share Posted May 4, 2007 thanks,shall i take exception number like err.number in VB Link to comment Share on other sites More sharing options...
jesh Posted May 4, 2007 Share Posted May 4, 2007 shall i take exception number like err.number in VBI typically don't worry about the number. The only things that I've found important, personally, are the Message, Source, and StackTrace. You can get at those like this:catch(SqlException sqe){ string message = sqe.Message; string source = sqe.Source; string trace = sqe.StackTrace;} If you're interested in the number, you can either use: int number = sqe.Number;// orint code = sqe.HResult; Check out the MSDN pages for more info on Exceptions:http://msdn2.microsoft.com/en-us/library/s....exception.aspx Link to comment Share on other sites More sharing options...
raviprakashg Posted May 9, 2007 Author Share Posted May 9, 2007 thanks a lot my friendursraviprakashg Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.