首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ Builder >

Windows下怎么获取除以零 这种异常

2012-03-11 
Windows下如何获取除以零 这种错误?Windows下如何获取除以零这种错误?还有就是如果设置一个进程的最大占用

Windows下如何获取除以零 这种错误?
Windows下如何获取除以零   这种错误?
还有就是如果设置一个进程的最大占用时间

[解决办法]
//在主窗体中建一个函数。
//.h文件
public:// User declarations
void __fastcall Tfor_Plus::AppLevelExceptionHandle(TObject *Sender,Exception *E);
//.cpp文件
void __fastcall Tfor_Plus::AppLevelExceptionHandle(TObject *Sender,Exception *E)
{
Screen-> Cursor = crDefault;
AnsiString sProcedureName;// = gsProcedureName;
gsProcedureName = " ";
AnsiString sText,sCaption;
sCaption = AnsiString(E-> ClassName());
AnsiString sCaption2;
AnsiString sCaptionUpperCase = sCaption.UpperCase();
if(sCaptionUpperCase == "EABORT "){
sCaption2 = "不显示错误消息框,终止事件序列 ";
}
else if(sCaptionUpperCase == "EDIVBYZERO "){
sCaption2 = "整数零除错误 ";
}
else if(sCaptionUpperCase == "EACCESSVIOLATION "){
sCaption2 = "内存访问错误 ";
}
else if(sCaptionUpperCase == "EBITSERROR "){
sCaption2 = "阻止对布尔型数组无效访问错误 ";
}
else if(sCaptionUpperCase == "ECOMPONENTERROR "){
sCaption2 = "注册或重命名组件错误 ";
}
else if(sCaptionUpperCase == "ECONVERTERROR "){
sCaption2 = "对象转换错误 ";
}
else if(sCaptionUpperCase == "EDATABASEERROR "){
sCaption2 = "数据库访问错误 ";
}
else if(sCaptionUpperCase == "EDBEDITERROR "){
sCaption2 = "与指定模式不兼容错误 ";
}
else if(sCaptionUpperCase == "EEXTERNALEXCEPTION "){
sCaption2 = "未识别异常代码 ";
}
else if(sCaptionUpperCase == "EINOUTERROR "){
sCaption2 = "文件输入输出错误 ";
}
else if(sCaptionUpperCase == "EINTOVERFLOW "){
sCaption2 = "寄存器溢出 ";
}
else if(sCaptionUpperCase == "EINVALIDCAST "){
sCaption2 = "非法类型转换错误 ";
}
else if(sCaptionUpperCase == "EINVALIDGRAPHIC "){
sCaption2 = "访问非法图形文件格式错误 ";
}
else if(sCaptionUpperCase == "EINVALIDOPERATION "){
sCaption2 = "组件非法操作错误 ";
}
else if(sCaptionUpperCase == "EINVALIDPOINTER "){
sCaption2 = "非法指针操作 ";
}
else if(sCaptionUpperCase == "EMENUERROR "){
sCaption2 = "菜单错误 ";
}
else if(sCaptionUpperCase == "EOLECTRLERROR "){
sCaption2 = "ActiveX控件错误 ";
}
else if(sCaptionUpperCase == "EOLEERROR "){
sCaption2 = "OLE自动化错误 ";
}
else if(sCaptionUpperCase == "EPRINTERERROR "){
sCaption2 = "打印错误 ";
}
else if(sCaptionUpperCase == "EPRINTERERROR "){
sCaption2 = "打印错误 ";
}
else if(sCaptionUpperCase == "EPROPERTYERROR "){
sCaption2 = "属性值错误 ";
}
else if(sCaptionUpperCase == "ERANGEERROR "){
sCaption2 = "整型数溢出 ";
}
else if(sCaptionUpperCase == "EREGISTRYEXCEPTION "){
sCaption2 = "注册表错误 ";
}
else if(sCaptionUpperCase == "ESTACKOVERFLOW "){
sCaption2 = "堆栈错误 ";
}
else if(sCaptionUpperCase == "EZERODIVIDE "){
sCaption2 = "浮点零除错误 ";


}
else{
sCaption2 = "未知错误 ";
}
sText = "ClassName = " + sCaption + "( " + sCaption2 + ")\r\n过程名 = " + sProcedureName + "\r\nMessage = " + E-> Message;
MessageBox(Handle,sText.c_str(),AnsiString(E-> ClassName()).c_str(),MB_OK|MB_ICONEXCLAMATION);
}

在每个窗体的OnCreate事件中写入
Application-> OnException = for_Plus-> AppLevelExceptionHandle;
[解决办法]
1.除零异常
int a=10;
int b=0;
int c;
try
{
c=a/b;
}
catch(EDivByZero &e)
{
ShowMessage(e.Message);//错误处理
}

2.根据实际情况Sleep();
[解决办法]
1. 应该改正代码错误, 而不要隐藏错误
2. 设置优先级比正常的低
[解决办法]
使用异常处理
int a=10;
int b=0;
int c;
try
{
c=a/b;
}
catch(EDivByZero &e)
{
ShowMessage(e.Message);//错误处理
}

[解决办法]
赞成cczlp的观点,不要隐藏错误。

热点排行