ArithmeticException: Overflow or underflow in the arithmetic operation



I've recently run into an issue with my windows forms application and
I'm hoping someone can shed some light on the issue. Essentially I have
a MDI app that fires an exception when I open a child form. It's
important to note that a) this only happens on one machine (the app has
been deployed on 2 PCs, tested on another PC and developed on yet
another machine), and b) this doesn't seem to happen all the time,
though it does happen most of the time.

The exception is as follows...

Exception Type: System.ArithmeticException
Message: Overflow or underflow in the arithmetic operation.
TargetSite: Void Initialize(System.Drawing.FontFamily, Single,
System.Drawing.FontStyle, System.Drawing.GraphicsUnit, Byte, Boolean)
HelpLink: NULL
Source: System.Drawing

Now, I've searched Google and Google Groups and found a number of
related posts and workarounds dating back to 2002. Unfortunately it
seems that no one agrees on the source of the's either
spyware, a bad driver separate from the application (perhaps a
printer?), or a bug in the .NET framework itself.

Microsoft has a KB article that appears to be related: "PRB:
System.Arithmetic Exception Error When You Change the Floating-Point
Control Register in a Managed Application" found here:

Unfortunately, I'm not making changing the floating-point register, nor
am I making calls to unmanaged code. What I *am* doing is this...

this.Comments.Font = new System.Drawing.Font("Microsoft Sans Serif",
8.25F, System.Drawing.FontStyle.Bold,
System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));

Another relevant post here in Groups can be found in this forum by
searching for "Bug in Font constructor". That post states that the
issue is caused by "a known bug in the Font constructor that occurs if
FPU exceptions are turned on" and suggests placing a [Try/Catch
ArithmeticException] block around the code that instantiates the form.
That's what I've done but while it works as a temp fix, this seems like
a lousy permanent solution.

Other posts have suggested API calls to manually the FPU off. I guess I
can do that but I cannot figure out *where* I need to make the API
call, nor how to make the call in C#. Also, if it's a bug, I'd rather
Microsoft had a fix for it.

I guess my point is this: this issue seems to have been around for
about 2 years now and no one seems to know what causes it or how to
really fix it. Does anyone have any suggestions or more info on the
issue? Any insights would be greatly appreciated. Thanks for your time!


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question