Jay Dee wrote:
[...]
And when the try section fales my excepton is thrown and if not court
elswair will display when debuging and hi-light the line:
throw new Exception("My Exception");
but when using other classes like in the microsoft framework library
the line that is hi-lighted is the line that called the class
containing that exception.
The difference there is basically because you don't have the source code
to the .NET code. So the debugger shows you the source code that is
closest to the thrown exception. If your own code throws an exception,
then that code is the code that threw the exception. But if some other
code throws an exception, then the closest code will still be in your
own code where it called the code for which the source code is absent.
What I am trying to say is that when my exception is thrown I no that
it has bean thrown but I don't know what corsed it to throw, so it is
fearly useles being there.
That's right. As Alvin says, it's not at all clear why you write the
code like that. You had a perfectly good exception. If you're not
going to handle it (that is, recover from it) then why hide it with a
whole new exception? Especially one that is a generic one, rather than
the original one.
At the very least, you could just write "throw;" instead of "throw new
Exception("My Exception");" At least that would cause the exception
thrown to be the same as the one that was caught. If I recall, the
stack trace will be wrong, but if you fix the "catch" statement so that
it declares a local ArgumentOutOfRangeException variable, then at least
you can look at that variable in the debugger and see what the stack
trace is (but only if you put a breakpoint before your own "throw"
statement, of course).
My experience has been that it's almost always a mistake to rethrow an
exception or throw a new exception from a "catch" clause. Sometimes
it's what you want to do, but usually it's better to either just handle
the error locally in the "catch" clause or put whatever cleanup code you
thought should go in the "catch" clause into the "finally" clause
instead, and just not catch any exception.
Pete