Is it possible? I didn't think so either. But read this.
I'm working now on a presentation regarding J2EE and .NET. For the sake of the presentation, I wanted to create error on one of the ASP.NET pages (yes, sometimes we do it just for fun. It's not a Bug, it's a Feature, you know...).
So, what is the easiest way to create an exception, I thought to myself? And immediately added the following code to the Page_Load event:
Response.write(1/0)
and executed the code. To my great surprise there was no exception! The page looked just normal. But while examining it more thoroughly, I found the following text on the upper left corner:
אינסוף חיובי
To those of you who can't read Hebrew (and I guess there are a handful of you), the meaning of those words are: Positive infinity.
WHAT? WTF? But wait - that's not all! When I modified the code to:
Response.write(-3/0)
The result was:
אינסוף שלילי
Which is:
Negative infinity.
Now, this is really strange:
First, since when a division by zero results in an infinity? I don't know much about math, but I asked my mother in law, who has a PhD in Mathematics, and she said that an expression like this is undefined, and definitely not infinity.
Second - localized math result? I liked that!
Anyway, here is an article which discusses this issue, but still does not explain when a division by zero is infinity. On the other side, in this article there is a good explanation why <Quote>division by zero is not defined for reals</Quote>, and when it is defined. Well worth reading.
So, does anybody know why division by zero is allowed in .NET?