# DivideByZeroException is only thrown in Mono builds, not in IL2CPP. Why?

I'm working on exception handling and I usually test it with causing a DivideByZeroException.

But this time it's not thrown. (While throwing a System.Exception works just like usual).

So I've created an empty project with only this script:

void Update()
{
if (Input.GetKeyDown(KeyCode.L))
{
Debug.Log("L");
var x = 0;
var y = 1 / x;
}
if (Input.GetKeyDown(KeyCode.P))
{
Debug.Log("P");
throw new System.Exception("test");
}
}


And with the empty project the DivideByZeroException is thrown, so I had a look on the project configurations.

Turns out the new project's Scripting Backend is Mono.

Once I changed it from Mono to IL2CPP, the DivideByZeroException is not thrown in this project as well.

I experimented with changing the API Compability Level, but they behave the same.

So last time I debugged exception handling, I was on Mono and then I changed it ... I guess to make it faster or something.

My question is: why is this the case?

• Wild guess: both variables get optimized out because they are not used May 6 at 12:45
• @user253751 Yes, you are probably right. I added a line: gameObject.name = y.ToString() so it's now used. Now it crashes when I press L. So yes, probably it was removed due to not being used. But then my followup question is: Why doesn't it just throw an exception? Instead of crashing alltogether? The System.Exception throwing hotkey still works just as it should: I press the key -> dev console appears with exception. May 6 at 13:19