Are these two code examples the same? Catch and Catch (Exception e) have the same output, and the result is also the same if I write Throw or Throw e.
Main:
try
{
A();
//B();
}
catch (Exception e)
{
Console.WriteLine("{0} exception caught.", e);
}
Code 1:
static void A()
{
try
{
int value = 1 / int.Parse("0");
}
catch (Exception e)
{
throw e;
}
}
Code 2:
static void A()
{
// Rethrow syntax.
try
{
int value = 1 / int.Parse("0");
}
catch
{
throw;
}
}
See Question&Answers more detail:os