haciendo referencia a una gran cantidad de documentación en la red, especialmente en SO, por ejemplo: What is the proper way to re-throw an exception in C#? debe haber una diferencia entre "throw e;" y "tirar".Throw VS rethrow: ¿el mismo resultado?
Pero, a partir de: http://bartdesmet.net/blogs/bart/archive/2006/03/12/3815.aspx,
este código:
using System;
class Ex
{
public static void Main()
{
//
// First test rethrowing the caught exception variable.
//
Console.WriteLine("First test");
try
{
ThrowWithVariable();
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
//
// Second test performing a blind rethrow.
//
Console.WriteLine("Second test");
try
{
ThrowWithoutVariable();
}
catch (Exception ex)
{
Console.WriteLine(ex.StackTrace);
}
}
private static void BadGuy()
{
//
// Some nasty behavior.
//
throw new Exception();
}
private static void ThrowWithVariable()
{
try
{
BadGuy();
}
catch (Exception ex)
{
throw ex;
}
}
private static void ThrowWithoutVariable()
{
try
{
BadGuy();
}
catch
{
throw;
}
}
}
da el siguiente resultado:
$ /cygdrive/c/Windows/Microsoft.NET/Framework/v4.0.30319/csc.exe Test.cs
Microsoft (R) Visual C# 2010 Compiler version 4.0.30319.1
Copyright (C) Microsoft Corporation. All rights reserved.
$ ./Test.exe
First test
at Ex.ThrowWithVariable()
at Ex.Main()
Second test
at Ex.ThrowWithoutVariable()
at Ex.Main()
que está en completa contradicción con la entrada de blog.
El mismo tipo de resultado se obtiene con el código de: http://crazorsharp.blogspot.com/2009/08/rethrowing-exception-without-resetting.html
pregunta original: ¿qué estoy haciendo mal?
ACTUALIZACIÓN: mismo resultado con .Net 3.5/csc.exe 3.5.30729.4926
SUMUP: todas sus respuestas fueron muy bien, gracias de nuevo.
Por lo tanto, la razón es efectiva debido al JITter de 64 bits.
tuviera que elegir una sola respuesta, y aquí es por eso que he elegido LukeH respuesta:
Supuso el problema procesos en línea y el hecho de que puede estar relacionado con mi arquitectura de 64 bits,
proporcionó la bandera NoInline, que es la forma más sencilla de evitar este comportamiento.
Sin embargo este número se eleva ahora otra pregunta: es este comportamiento compatible con todas las especificaciones .Net: los CLR y los C# los lenguajes de programación?
ACTUALIZACIÓN: esta optimización parece compatible en función de: Throw VS rethrow : same result? (gracias 0xA3)
Gracias de antemano por su ayuda.
Tiene razón, usar la bandera NoInlining hizo el truco. Gracias. – Pragmateek