You'd want to go with the message boxes in this case. Exceptions are
supposed to be "exceptional" situations that aren't otherwise easily
handled.
You want to avoid using them excessively and particularly in code that's
performance critical. There's a large performance cost in throwing an
exception that comes in part from having to unwind the stack. So, for
example, if you have a loop reading data from a large set of data, you
wouldn't want it to throw exceptions for every 4th row, say, because a bit
of the data is formatted incorrectly (unless you want to throw the exception
and end the loop). If you were to catch the exception, handle it, and then
continue reading data, the performance hit would likely be very noticeable.
Instead you'd simply discard the data or try to deal with the unexpected
formatting in the code without exceptions.
That's not to say that you should avoid exceptions, you just don't want to
be throwing them often. Generally, you want an exception to mean that
there's something wrong and unexpected taking place that the code in
question can't deal with.
Pete
"perspolis" <re*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi
I have a question about using exceptions or showing error messages .I say
this by an example
first way:
if(n<0 and w<0)
MessageBox.Show("please enter positive")
else if (n=0 or w>0)
MessageBox.show("n is 0");
or second way
try
{
if(n<0 and w<0)
throw new Exception("please enter positive")
else if (n=0 or w>0)
throw new Exception("n is 0");
}
catch(Exception err)
{
MessageBox.show(err.Message);
}
thanks in advance