Jump to content

exception for unique key or primary key


raviprakashg

Recommended Posts

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

shall i take exception number like err.number in VB
I 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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...