Catch vs Catch (Ausnahme e) und Throw vs Throw e
Sind diese beiden Codebeispiele gleich?Fang undFang (Ausnahme e) habe die gleiche Ausgabe, und das Ergebnis ist auch das gleiche, wenn ich schreibeWerfen oderWirf 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;
}
}