giving error message according to Sql data
-
Dave Kreskowiak wrote:
If a known condition can be tested for without relying on an exception, it's a best course of action.
Well, I wouldn't say that's always true. Imagine if TryParse didn't exist. Would you rather Try/Catch a Parse or re-implement a version of parse that returns a bool if the string is invalid? Given the complexity of number formats (e.g., scientific notation), I would just do a Try/Catch. I guess this can be generalized as: If a known condition is exceptionally complex to test for, then just use exception handling to test if it's valid. Here's another example. I built a tool that allows the user to enter a regular expression to match against some data. Rather than validate that the regular expression is valid, I just used Try/Catch to catch exceptions thrown by invalid exceptions. I mean I COULD first check if the regular expression is valid, but it would be exceedingly complex and a waste of time when the test for validity already exists in the form of exception handling.
aspdotnetdev wrote:
Imagine if TryParse didn't exist.
It didn't at one point. I said if it could be tested for. Obviously, you can't test for every possible failure in a Parse method. It's not practical since there are just too many possibilities. But, you can test for a single known condition, like a duplicate key.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak -
Fair enough. Regardless, this is a good discussion.
I know the language. I've read a book. - _Madmatt
Mark Nischalke wrote:
Regardless, this is a good discussion.
Oh yes, in fact I wish we had more of these in the Lounge :-)
Regards, Nish
My technology blog: voidnish.wordpress.com
-
hey guys thanks for all your replies i use MsSql 2008 express..and i tried something like that
try
{
dr[j] = xnl.Item(i).ChildNodes[j].InnerText;
}
catch(SqlException ex)
{
Console.WriteLine("This Record is already exist");
}but still on the screen it shows the same error which is shown in Sql screen and sometimes it gives error like object reference not set to an instance of an object in that line dr[j] = xnl.Item(i).ChildNodes[j].InnerText; what is wrong here.i read a Xml file over website and put it in a datatable is it because it cannot connect that site ?
modified on Thursday, December 9, 2010 4:20 AM
In this case, I'd suspect that xml.Item(i) doesn't have any child nodes, so attempting to do anything with it would cause a problem.
I'm not a stalker, I just know things. Oh by the way, you're out of milk.
Forgive your enemies - it messes with their heads