On Wed, 29 Nov 2006 12:36:40 +0100, "Adrian <" <no*@all.accessible>
wrote:
>If I code as follows
try
{
\\ do something
}
catch (.....Exception)
{
throw;
}
What should happen?
A test program isn't doing what I had expected it would do.
Hence this question.
Adrian.
That depends on what you expected it to do. Currently your code just
rethrows the original exception, so unless you have another catch
statement somewhere the exception will remain uncaught and the program
will crash, at the point of your "throw", with an uncaught exception.
When I run:
static void Main() {
try {
int x = 20;
int y = 0;
int z = x / y;
}
catch (DivideByZeroException) {
Console.WriteLine("Inside catch.");
throw;
}
Console.Write("Press [Enter] to continue... ");
Console.ReadLine();
}
I get "Inside catch." displayed on the console and then the program
crashes with an uncaught DivideByZero exception, as I would expect it
to. Also, the crash happened at the "throw" and not at the "z = x /
y". The original exception was correctly caught, it is the
re-throwing of the exception that is not caught and causes the actual
crash.
rossum