急!!!关于“runtime error”的问题。

wangsiyuanoo 2010-12-09 12:30:55
做下面工作的时候会不定时的出现:
“runtime error”错误。
请大牛们帮我分析一下,会是神马情况才会出现这种错误呢?
PS:基本排除数组越界之类的错误。

还有,如何用try/catch捕获错误呢?


CMySqlDatabase mysql;
bool bLink = GetConnectSQL(mysql);
bool bAlive = mysql.IsConnAlive();
if ( bLink && bAlive )
{
do
{
try
{
//循环执行SQL语句
}
catch (CException* e)
{
//请问,这里应该怎么写,才能捕获到错误描述。
}
}
while ();
}
...全文
125 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yihandrensunyong 2010-12-09
  • 打赏
  • 举报
回复
把可能产生错误的带代码 放到TRY里面执行
lucky-lucky 2010-12-09
  • 打赏
  • 举报
回复
百度百科里将try讲的很详细
http://baike.baidu.com/view/388893.htm
luciferisnotsatan 2010-12-09
  • 打赏
  • 举报
回复
CException* e 这个e就是抛出的异常。用成员函数GetErrorMessage 得到信息。
wangsiyuanoo 2010-12-09
  • 打赏
  • 举报
回复
try
{
//循环执行SQL语句
}
catch (CException* e) //mfc的异常
{
char strError[MAX_PATH] = {0};
e->GetErrorMessage( strError, MAX_PATH );
MessageBox( strError, "错误", MB_ICONSTOP );
}
catch (...) //非mfc的异常
{
DWORD dwError = GetLastError();
char strError[MAX_PATH] = {0};
sprintf( strError, "代码:%d", dwError );
MessageBox( strError, "错误", MB_ICONSTOP );
}

这样写可以么?
因为我觉得错误不一定是mfc异常,如果是非MFC异常呢,我这样写会不会两者都得到?
Nov_c 2010-12-09
  • 打赏
  • 举报
回复
GetErrorMessage or ReportError
wyfwx 2010-12-09
  • 打赏
  • 举报
回复
CException
1 下载 Myeclipse Axis2 插件 http: archive apache org dist ws axis2 tools 1 4 1 下载 axis2 eclipse codegen wizard zip 和 axis2 eclipse service archiver wizard zip http: labs xiaonei com apache mirror ws axis2 1 5 axis2 1 5 war zip 下载 axis2 1 5 war zip 2 .解压插件 $ECLIPSE HOME 表示你安装的 myeclipse 主目录 将上述两个插件都解压到 $ECLIPSE HOME eclipse plugins 目录中; Axis2 Codegen Wizard 1 3 0 和 Axis2 Service Archiver 1 3 0 3 在 $ECLIPSE HOME eclipse links 目录下增加文件 axis eclipse plugin link 写入 path $ECLIPSE HOME eclipse plugins 千万不要直接复制 4 重新启动 myeclipse 在 file >new >other 中即可看到 Axis2 Wizards 至此 axis2 插件安装成功 GXGX 5 赶快试下用 wsdl 文件生成 java 源文件吧 是不是有错误出现 对 事情就是这样发展的 6 An error occurred while completing process java lang reflect InvocationTargetException 的错误 嗯不用 有得解 不过我当初很惨弄了一个晚上 解决方法如下: step 1 从 AXIS2 的 LIB 库中复制 "geronimo stax api 1 0 spec 1 0 1 jar" 和 "backport util concurrent 3 1 jar" 文件到 Axis2 Codegen Wizard 1 3 0 的 lib 目录中 同时修改 Axis2 Codegen Wizard 1 3 0 下的 plugin xml 文件 在 <runtime> 中添加 <library name "lib geronimo stax api 1 0 spec 1 0 1 jar"> <export name " " > < library> <library name "lib backport util concurrent 3 1 jar"> <export name " " > < library> 到 plugin xml 文件中 保存 step 2 将 $workspace 位置 metadata plugins 下目录 Axis2 Codegen Wizard 删除 step 3 在命令行下切换至 $ECLIPSE HOME 目录 然后执行: eclipse –clear step 4 除了上面步骤还要: (4 1) 把Axis2 Codegen wizard 1 3 0 eclipse plugins Axis2 Codegen wizard 1 3 0 的名字改成Axis2 Codegen wizard 1 4 0 (4 2) 在plugin xml中在<plugin>中 把Axis2 Codegen wizard的version "1 3 0"改成version "1 4 0" 到plugin xml文件中 保存后重新启动Eclipse即可 ">1 下载 Myeclipse Axis2 插件 http: archive apache org dist ws axis2 tools 1 4 1 下载 axis2 eclipse codegen wizard zip 和 axis2 eclipse service archiver wizard zip http: labs xiaonei com apache mirror ws axis2 1 5 axis2 1 5 war zip 下载 axis2 1 5 war zip 2 .解压插件 $E [更多]

64,646

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧