`
aijuans8
  • 浏览: 178386 次
社区版块
存档分类
最新评论

.Net中使用com组件后发生System.ArithmeticException异常的解决办法

 
阅读更多

最近在开发一个.Net程序,其中涉及到对com组件的调用,在调用完以后如果使用一些小的测试程序继续运行,一切正常,但是在使用带有GUI的form程序继续执行时,总是出现以下异常
Exception: System.ArithmeticException
Message: 算术运算中发生溢出或下溢。
Source: System.Drawing
at System.Drawing.Font.Initialize(FontFamily family, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet, Boolean gdiVerticalFont)
at System.Drawing.Font..ctor(String familyName, Single emSize, FontStyle style, GraphicsUnit unit, Byte gdiCharSet)
at Payment.Phone.ErrorForm.InitializeComponent() in E:/cvsroot/develope/payment/Phone/ErrorForm.cs:line 108
at Payment.Phone.ErrorForm..ctor(Util util, String msg) in E:/cvsroot/develope/payment/Phone/ErrorForm.cs:line 139
at Payment.Phone.ConfirmForm.lblNext_Click(Object sender, EventArgs e) in E:/cvsroot/develope/payment/Phone/ConfirmForm.cs:line 212

后来到处找资料,花了我一天的时间才给解决,以下是我的解决办法:
1.声明一个DLL掉用
[DllImport("msvcr70.dll", CallingConvention = CallingConvention.Cdecl)]
unsafe public static extern int _controlfp(int n, int mask);
2.在代码中添加以下代码方法
internal void ResetFPCR()
{
const int _EM_OVERFLOW = 0x0009001F;
const int _MCW_EM = 0x000FFFFF;
_controlfp(_EM_OVERFLOW, _MCW_EM);
}
3.在调用完com组件后,调用以上方法,如:
//这里调用com组件

//然后执行Reset方法
ResetFPCR();

注:具体详细请看http://support.microsoft.com/default.aspx?scid=KB;EN-US;q326219&

分享到:
评论

相关推荐

    java 除0发生的算术异常(ArithmeticException)

    java 除0发生的算术异常(ArithmeticException) java 除0发生的算术异常(ArithmeticException)

    在Java中异常分析

    在初学java中一般都会出现各种异常!比如: NO.3 java.lang.ArithmeticException java.lang.Object java.lang.Throwable java.lang.Exception java.lang.RuntimeException java.lang.ArithmeticException ...

    vb.net基本入门学习资料.doc

    vb.net基础教程 第一部分 Visual Basic.net基础 1.vb. net介绍 2.vb.net的优点 3.新建一个vb.net项目 4.编写第一个vb.net应用程序 第二部分 vb.net的语法部分 1.vb.net的Numeric数据类型 2.vb.net的Byte数据类型 3....

    vb.net基本入门学习资料

    第一部分 Visual Basic.net基础 1.vb. net介绍 2.vb.net的优点 3.新建一个vb.net项目 4.编写第一个vb.net应用程序 第二部分 vb.net的语法部分 1.vb.net的Numeric数据类型 2.vb.net的Byte数据类型 3.vb.net的String...

    GTM007.A.Course.in.Arithmetic,.Jean-Pierre.Serre.(数论教程)(1).djvu

    A.Course.in.Arithmetic,.Jean-Pierre.Serre,数论教程

    Java中的异常处理机制.md

    异常检测 ​ 在Java中,异常处理是一种用于处理在程序执行期间可能出现的错误或异常条件的机制。这种机制允许程序员定义在特定... System.out.println("发生了除以零的异常: " + e.getMessage()); } catch (Excepti

    Synthesis.of.Arithmetic.Circuits.FPGA.ASIC.and.Embedded.Systems.

    was born: computer arithmetic. Traditionally, the study of arithmetic circuits has been oriented toward applications to general-purpose computers, which provide the most important applications of ...

    将 BigDecimal 类型转换为 Integer 类型.pdf

    当 BigDecimal 值大于 Integer.MAX_VALUE 时,intValue() 方法将抛出 java.lang.ArithmeticException 异常。例如,在上面的示例代码中,若输入的 BigDecimal 值为 2147483648 时,intValue() 方法将抛出“Out of ...

    Google C++ International Standard.pdf

    Contents Contents ii List of Tables x List of Figures xiv 1 Scope 1 2 Normative references 2 3 Terms and definitions 3 4 General principles 7 4.1 Implementation compliance . ....4.2 Structure of this ...

    C++ 标准 ISO 14882-2011

    Contents Contents iii List of Tables xi List of Figures xv 1 General 1 1.1 Scope . . . . ....1.2 Normative references ....1.3 Terms and definitions ....1.4 Implementation compliance ....1.5 Structure of this ...

    JavaSE 异常处理.pdf

    其中,ExceptionType表示捕获的异常类型,可以是Java中任何一个异常类的名称,如ArithmeticException、NullPointerException等等。当在try块中的代码发生了与ExceptionType相匹配的异常时,程序会跳转到catch块中...

    异常以及异常中常用到的类

    在这里我们必须要明白无论会不会出现异常,finally代码块里面的代码都是必须执行的,finally块不执行的唯一情况是:在异常处理代码中执行System.exit(1),将退出java虚拟机! 最后我写点我们在学习和工作的时候常见的...

    Java异常处理.md

    - 当代码执行过程中出现如除数为零的`ArithmeticException`等错误时,Java会立即转至相应的catch块进行异常处理,如输出错误信息并打印堆栈跟踪。 2. **finally块的使用**: - 不论try块中的代码是否抛出异常,...

    表达式解析组件

    C#开发的表达式分析程序,内置常用的数学函数和字符串处理函数,支持外部自定义函数计算,函数嵌套计算。 欢迎各位使用参考,请大家多提宝贵意见! 我的Email:shaoqiang@citiz.net ...4.ArithMetic.dll

    最新NIIT考试题目

    catch( ArithmeticException e ) { System.out.println("Catch "); } catch( Exception e ) { System.out.println("Will not be executed");} finally{ System.out.println("finally"); } } public static ...

    捕捉除数=0异常.rar

    题目:输入两个整数将其整除,用try-catch语句捕获除数为0的异常。 本代码是c#语言编写的关于异常处理的代码,运行正常。

    JSTL详细标签库介绍

    完成异常处理的功能,因为可能除数为0是会出现异常,我们查找java.lang包中各个Exception类,发现RuntimeException类集合中的ArithmeticException可以处理运算异常,我们就让一个DivideByZeroException(继承于...

    Java提高篇——Java异常处理

    如果你用System.out.println(11/0),那么你是因为你用0做了除数,会抛出java.lang.ArithmeticException的异常。异常发生的原因有很多,通常包含以下几大类:用户输入了非法数据。要打开的文件不存在。网络通信时连接...

    Java 异常处理

    如果你用System.out.println(11/0),那么你是因为你用0做了除数,会抛出 java.lang.ArithmeticException 的异常。 异常发生的原因有很多,通常包含以下几大类: 用户输入了非法数据。 要打开的文件不存在。 网络通信...

Global site tag (gtag.js) - Google Analytics