项目仅在调试模式下引发异常 [英] Project throws exception only in debug mode

查看:145
本文介绍了项目仅在调试模式下引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,直到最近才在Visual Studio 6.0中进行了编译,没有任何问题.我将此项目移到了Visual Studio2008.
在调试和发布模式下都可以正确编译.

它打开一个MS Access数据库文件并访问一个表.

它在发布模式下工作正常,但是当我尝试在调试模式下运行项目时,它将引发异常.在访问表后发生异常,我尝试移至下一条记录.

我已经复制了一些表明可能存在问题的输出.

感谢您的帮助.

I have a project that until recently was compiled in Visual Studio 6.0 with no problems. I moved this project to Visual Studio 2008.
It compiles without error in both debug and release mode.

It opens up a MS Access database file and accesses a table.

It works fine in Release Mode, but when I attempt to run the project in Debug mode it throws an exception. The exception occurs after the table is accessed and I attempt to move to the next record.

I have copied some of the output that indicates a possible problem.

Thanks for your help.

'Proj.exe': Loaded 'C:\WINDOWS\system32\odbcint.dll', Binary was not built with debug information.

Warning: ODBC Success With Info, Driver's SQLSetConnectAttr failed
State:IM006,Native : 0,Origin:[Microsoft][ODBC Driver Manager]

DBMS: ACCESS
Version: 04.00.0000
ODBC Driver Manager Version: 03.52.0000
Warning: ODBC Success With Info, String data, right truncated 
State:01004,Native:5,Origin:[Microsoft][ODBC Microsoft Access Driver]

'Proj.exe': Loaded 'C:\WINDOWS\system32\expsrv.dll', Cannot find or open a required DBG file.
Warning: Setting forwardOnly recordset readOnly.

推荐答案

可能有不同的原因.顺便说一句,您提供的是输出,而不是异常.请提供完整的异常转储,并在发生异常时显示类似的代码.为什么要强迫我们进行猜测?

无论如何,都有典型的常见问题导致这种情况.可能最常见的是由于对文件路径的错误假设而导致无法在其中一种配置中找到某些文件.顺便说一句,即使在Release配置中,也可以使用Debugger.差异很可能不是由于在调试器下运行,而是由于项目配置不同而导致的,这是不一样的.在带有发布配置的调试器下运行;您可能会看到是否仍然找不到该文件.

在运行时,您永远不应假定任何特定的工作目录.工作目录取决于Configuration,但实际上它是由用户在启动应用程序时定义的.绝对不要使用绝对路径,也不要因为环境变量而假定该路径是可见的.这意味着您需要在运行时计算数据文件的路径.此路径可以是相对于您的可执行模块的路径(但通常仅是在不可变数据的情况下)或特定目录之一,例如所有用户"应用程序数据等.


进一步了解问题需要更多的异常信息.首先,代码行发生的地方.由于您的问题在Debugger中得到了体现,所以这并不难:您可以捕获异常,在捕获异常的地方放置一个断点,并使用Visual Studio Debug->查找堆栈. Windows->调用堆栈.这足以在发生的代码中找到我们的代码,以便在CodeProject问题中进行报告.

以编程方式转储它比较困难.我尚未在C ++中完成此操作(在.NET中是标准API的一部分),但Google搜索显示一个简单的C ++函数调用堆栈跟踪实用程序 [ ^ ], http://stackoverflow.com/questions/3355683/c-stack-trace -from-unhandled-exception [ ^ ], http://stackoverflow.com/questions/1796225 /get-stack-trace-from-uncaught-exception [
There can be different reasons. By the way, you provide output, not exception. Please, provide full exception dump and show the like of code where it happens. Why forcing us into guesswork?

Anyway, there are typical common problems which cause such situation. Maybe most usual of them is the failure to find some file(s) in one of the configurations, because of incorrect assumptions on the file path. By the way, you can use the Debugger even in Release configuration. The difference is, most likely, not due to running under the debugger, but due to different project configuration, which is not the same. Run under debugger with Release configuration; and you will probably see if the file is still not found.

You should never assume any certain work directory during run-time. The working directory depends on Configuration, but in fact it is defined by the user at the moment of starting the application. You should never use absolute path or assume the path is visible due to Environment variable(s). It means you need to calculate the path to your data file during run-time. This path can be relative to your executable module (but usually only if this is immutable data) or one of the special directories, such as "All users" application data, etc.


Getting to further detail of the problem needs more exception information; first of all, lines of code where it happens. As your problem is manifested under Debugger, this is not too hard: you can catch exception, put a break point where exception is caught and look for stack using Visual Studio Debug -> Windows -> Call stack. This can be enough to find our there in code it happens for the purpose of reporting it in the CodeProject Question.

Dumping it programmatically is a bit more difficult; I haven''t done it in C++ (in .NET its part of standard API), but Google search shows A Simple C++ Function Call Stack Trace Utility[^], http://stackoverflow.com/questions/3355683/c-stack-trace-from-unhandled-exception[^], http://stackoverflow.com/questions/1796225/get-stack-trace-from-uncaught-exception[^].

—SA


该消息表明调试器无法找到dbg文件,仅是信息,而不是错误.您的程序应在有或没有它的情况下运行.

以及警告:将forwardSet记录集设置为readOnly."只是警告,您在使用forwardOnly时应在选项中设置readOnly标志,而您的记录集类会为您做到这一点.

好吧,这使我们完全没有错误信息.

我建议您追溯到您可以控制的代码的最后一点,并开始检查您所做的所有系统调用的参数值.
The message saying the debugger cannot find a dbg file, is just information, not an error. Your program should run with or without it.

And "Warning: Setting forwardOnly recordset readOnly." is just a warning saying you should have set the readOnly flag in the options when using forwardOnly, and that your record set class does it for you.

Well, that leaves us with no error information at all.

I suggest you trace back to the last point in the code you have control, and start checking parameter values to all system calls you make.


我知道我没有太大帮助,但是我正在尝试.该应用程序已经运行了两年,没有任何问题.现在,它已在Visual Studio 2008中运行,无法在调试模式下使用.释放模式很好.这是炸毁的地方.在返回语句之后.返回AfxCallWndProc(pWnd,hWnd,nMsg,wParam,lParam);

前三个参数具有地址,而wParam和lParam没有.当我尝试移至下一条记录时,发生错误.希望能有所帮助.
I know I''m not helping much but I''m trying. This application has been working for two years without a problem. Now that it is in Visual Studio 2008 it doesn''t work in Debug mode. Release mode is fine. Here is where it blows up. After the return statement. return AfxCallWndProc(pWnd, hWnd, nMsg, wParam, lParam);

The first 3 parameters have addresses while wParam and lParam do not. The error occurs when I attempt to move to the next record. Hope that helps.
AfxWndProc(HWND hWnd, UINT nMsg, WPARAM wParam, LPARAM lParam) { // special message which identifies the window as using AfxWndProc if (nMsg == WM_QUERYAFXWNDPROC) return 1; // all other messages route through message map 

CWnd* pWnd = CWnd::FromHandlePermanent(hWnd); 
ASSERT(pWnd != NULL); 
ASSERT pWnd==NULL || pWnd->m_hWnd == hWnd); 
if (pWnd == NULL || pWnd->m_hWnd != hWnd) 
     return ::DefWindowProc(hWnd, nMsg, wParam, lParam); 

return AfxCallWndProc(pWnd, hWnd, nMsg, wParam, lParam); 
}


这篇关于项目仅在调试模式下引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆