Are you sure? I know that the C# compiler certainly will for a similar piece of code when building with optimisations, although it will leave it if you don't enable optimisations. eg.
Code:
class Program
{
private static void Main(string[] args)
{
while (true)
{
int p = new int();
}
}
}
Spits out this CIL without optimisations:
Code:
.method private hidebysig static
void Main (
string[] args
) cil managed
{
// Method begins at RVA 0x2050
// Code size 11 (0xb)
.maxstack 1
.entrypoint
.locals init (
[0] int32 p,
[1] bool CS$4$0000
)
IL_0000: nop
IL_0001: br.s IL_0007
// loop start (head: IL_0007)
IL_0003: nop
IL_0004: ldc.i4.0
IL_0005: stloc.0
IL_0006: nop
IL_0007: ldc.i4.1
IL_0008: stloc.1
IL_0009: br.s IL_0003
// end loop
} // end of method Program::Main
And with optimisations:
Code:
.method private hidebysig static
void Main (
string[] args
) cil managed
{
// Method begins at RVA 0x2050
// Code size 2 (0x2)
.maxstack 8
.entrypoint
// loop start
IL_0000: br.s IL_0000
// end loop
} // end of method Program::Main
Obviously the compilers are different, but I'd imagine that those two that you mentioned would do something similar providing you enable the right optimisations.
@OP: Can't you just throw the exception manually? :lol: