未处理的异常 - 在调试器和非调试器下不同 [英] Unhandled exception - Different under debugger and non-debugger

查看:70
本文介绍了未处理的异常 - 在调试器和非调试器下不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的代码在

调试器下运行,我会得到不同的行为。


我修改了Winmain,如下所示:


//版权所有(C)2002 Microsoft Corporation

//保留所有权利。

//此代码和信息是提供按原样不保证

任何种类,无论是
//表达或暗示,包括但不限于暗示

保证

//适应性和/或针对特定用途的适用性。


//需要Visual Studio .NET的试用版或发行版

专业版(或更高)。


#include" stdafx.h"

#include" frmMain.h"

#使用命名空间VCNET包含MyException.h


;


[System :: STAThreadAttribute]

void __stdcall WinMain()

{

尝试

{

Application :: Run(new frmMain());

}

catch(MyException * pMyException)

{

//向用户显示例外。

MessageBox :: Show



System :: String :: Concat



MyException-> ShowFullMessage(),

S" \\\\\ n&n;,

S内部失败。程序终止。

),

S内部失败。程序终止。,

MessageBoxButtons :: OK,

MessageBoxIcon ::错误

);

}

}

在按钮处理程序中,我抛出一个MyException。


在调试器下,WinMain中捕获异常正确显示
对话框。


如果我运行可执行文件(Release或Debugger版本),那么

异常是未被捕获,系统显示未处理的异常

消息。未处理的消息显示正确的信息。存储在MyException对象中的



不可否认,异常是从函数中抛出三十级
通过一堆

系统dll在函数和WinMain()之间进行
的过程调用。


尽管如此,我不会指望不同的行为如果程序是在调试器下运行而没有调试器的


I''m getting different behavior if my code is running under the
debugger or not.

I have modified Winmain to look like this:

// Copyright (C) 2002 Microsoft Corporation
// All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER
// EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
WARRANTIES OF
// MERCHANTIBILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

// Requires the Trial or Release version of Visual Studio .NET
Professional (or greater).

#include "stdafx.h"
#include "frmMain.h"
#include "MyException.h"

using namespace VCNET;

[System::STAThreadAttribute]
void __stdcall WinMain()
{
try
{
Application::Run(new frmMain());
}
catch (MyException* pMyException)
{
// Show the exception to the user.
MessageBox::Show
(
System::String::Concat
(
MyException->ShowFullMessage(),
S"\r\n\r\n",
S"Internal failure. Program terminates."
),
S"Internal failure. Program terminates.",
MessageBoxButtons::OK,
MessageBoxIcon::Error
);
}
}
In a button handler I throw a MyException.

Under the debugger, the exception is caught in WinMain and a proper
dialog box is displayed.

If I run the executable (either Release or Debugger builds) then the
exception is not caught and the system displays an unhandled exception
message. The unhandled message displays the proper information.stored
in the MyException object.

Admittedly, the exception is being thrown from a function thirty levels
of procedure call between the function and WinMain() through a bunch of
system dlls.

Nonetheless, I would not expect different behavior if the program is
running under the debugger and without the debugger.

推荐答案

我发现如果你更改:


int __stdcall WinMain(无效)


作为''主要''的通话格式:

int _tmain(void)


异常消失了。但是,这会打开黑色控制台

屏幕,我需要消除它。所以我有问题(在我的情况下)

半解决了...... :)


[== P ==]

RalphTheExpert < RA **** @ dos32.com>在消息中写道

news:11 ********************** @ g44g2000cwa.googlegr oups.com ...
I have found if you change:

int __stdcall WinMain(void)

as the ''main'' call format to:

int _tmain(void)

that the exception goes away for me. BUT, this brings up the black Console
screen, which I need to eliminate. So I have the problem (in my case)
half-solved... : )

[==P==]
"RalphTheExpert" <ra****@dos32.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
如果我的代码在
调试器下运行,我会得到不同的行为。

我修改了Winmain看起来像这样:
//版权所有(C)2002 Microsoft Corporation
//保留所有权利。
//本规范和信息按原样提供。不提供任何形式的保证,无论是表达还是暗示,包括但不限于
//适销性和/或针对特定用途的适用性的暗示
保证。

//需要Visual Studio .NET的试用版或发行版
Professional(或更高版本)。

#include" stdafx.h"
#include" frmMain.h"
#include" MyException.h"
使用命名空间VCNET;

[System :: STAThreadAttribute]
void __stdcall WinMain()
{
尝试
应用程序::运行(新frmMain());
}
catch(MyException * pMyException )
{
//向用户显示例外。
MessageBox :: Show

System :: String :: Concat

MyException-> ShowFullMessage(),
S" \\\\\\\ n",
S"内部失败。程序终止。
),
S"内部失败。程序终止。,MessageBoxB uttons :: OK,
MessageBoxIcon ::错误
);
}
}
在按钮处理程序中,我抛出一个MyException。

在调试器下,异常会在WinMain中捕获,并显示一个正确的
对话框。

如果我运行可执行文件(Release或Debugger版本),那么
异常未被捕获,系统显示未处理的异常消息。未处理的消息显示正确的信息。存储在MyException对象中。

不可否认,异常是从函数和函数WinMain之间的函数调用的三十个级别抛出的异常()通过一堆
系统dll。

但是,如果程序在调试器下运行而没有调试器,我不会指望不同的行为。
I''m getting different behavior if my code is running under the
debugger or not.

I have modified Winmain to look like this:

// Copyright (C) 2002 Microsoft Corporation
// All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER
// EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
WARRANTIES OF
// MERCHANTIBILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

// Requires the Trial or Release version of Visual Studio .NET
Professional (or greater).

#include "stdafx.h"
#include "frmMain.h"
#include "MyException.h"

using namespace VCNET;

[System::STAThreadAttribute]
void __stdcall WinMain()
{
try
{
Application::Run(new frmMain());
}
catch (MyException* pMyException)
{
// Show the exception to the user.
MessageBox::Show
(
System::String::Concat
(
MyException->ShowFullMessage(),
S"\r\n\r\n",
S"Internal failure. Program terminates."
),
S"Internal failure. Program terminates.",
MessageBoxButtons::OK,
MessageBoxIcon::Error
);
}
}
In a button handler I throw a MyException.

Under the debugger, the exception is caught in WinMain and a proper
dialog box is displayed.

If I run the executable (either Release or Debugger builds) then the
exception is not caught and the system displays an unhandled exception
message. The unhandled message displays the proper information.stored
in the MyException object.

Admittedly, the exception is being thrown from a function thirty levels
of procedure call between the function and WinMain() through a bunch of
system dlls.

Nonetheless, I would not expect different behavior if the program is
running under the debugger and without the debugger.



我的猜测是控制台屏幕出现,因为你指定了链接器选项子系统是控制台而不是windows的




如果程序是控制台,那么环境要简单得多,而且b / b $ b $之间的掷骰可能会少得多。

我依旧记得在VC 6中遇到同样的问题。如果我的记忆是正确的,那么尝试从消息内部进行抛出是不好的

泵到一个外面。

我知道l在/子系统中MC ++内部的一点点:windows

环境。我甚至不确定是否有消息泵。


尽管如此,我肯定想知道从
$扔一下是否合法b $ b在消息处理程序中一直到WinMain。

My guess is that the console screen comes up because you have specified
that the linker option, subsystem, is console rather than than windows.

If the program is console then the envirnoment is much simpler and
there are likely far fewer dlls between a throw and the catch.
I vaguely remember haveing the same problem in VC 6. If my memory is
correct, it was bad to attempt to do a throw from inside of a message
pump to outside of one.
I know fairly little of the internals of MC++ in a /subsystem:windows
environment. I''m not even sure if there is a message pump.

Nonetheless, I''d sure like to know if it is legal to do a throw from
inside a message handler all the way out to WinMain.


我检查过,它是''未设置''。当我将它设置为/ SUBSYSTEM:WINDOWS它

会给我一个编译器错误,除非我使用int __stdcall WinMain(void)作为

''main''调用应用程序,在这种情况下,它没有提出

控制台,但退出时出现异常错误。如果我将它设置为

/ SUBSYSTEM :: CONSOLE我得到编译器错误,除非我使用int _tmain(void)作为

对应用程序的'main'调用,在这种情况下,它会调出控制台

并且退出时没有异常错误。


因此,它与我离开它时的行为没有什么不同未设置只是

改变了主要电话的形式。我能想到一个

程序应该产生异常错误的原因没有任何理由(你知道,这种情况会导致你想要发送这个问题吗?到MS进行分析?''对话框)

除非它使用控制台。这可能意味着问题不在我的

应用程序代码中,而是在项目的某些设置中。由于2003年没有发生过这样的事情,我怎么会想知道是什么造成了这个例外

(它吐出的信息并不明显)帮助,它只是说它有一个

异常错误并退出代码:-1073740791(0xc0000409)。哦,好吧,

不是很有帮助吗?;)


有人想。我允许2005年将我的应用程序从2003年转换为2005年。

当我从2002年到2003年的一个项目中做到这一点时,结果显示

转换并不完全成功, 3个星期后我遇到了一个错误

,只能通过打开一个新的2003项目并将

源复制到上一个项目中来解决(它一直告诉我我在链接器中使用了一个

过时的版本,但有趣的是,这个

警告仅在我完成转换后的几周内开始发生,在

这次我对代码进行了大量的更改和添加。是否可能2003年至2005年的转换也存在问题?


[== P ==]


RalphTheExpert < RA **** @ dos32.com>在消息中写道

news:11 ********************** @ g14g2000cwa.googlegr oups.com ...
I checked, and it was at ''Not Set''. When I set it to /SUBSYSTEM:WINDOWS it
will give me a compiler error unless I use int __stdcall WinMain(void) as
the ''main'' call to the application, in which case it doesn''t bring up the
Console but does exit with an exception error. If I set it to
/SUBSYSTEM::CONSOLE I get a compiler error unless I use int _tmain(void) as
the ''main'' call to the application, in which case it brings up the Console
and there is no exception error on exit.

Thus, it behaves no different than if I left it to ''Not Set'' and just
changed the form of the ''main'' call. I can think of no good reason that a
program should produce an exception error (you know, the kind that brings up
the ''do you want to send this problem to MS for analysis?'' dialog box)
UNLESS its uses a Console. This probably means the problem isn''t in my
application code, but in some setup of the project. Since this didn''t happen
in 2003, how in hell am I suppose to find out what is causing the exception
(the info it spits out is of no apparent help, it just says it got an
exception error and exits with code: -1073740791 (0xc0000409). Oh goody,
isn''t that helpful? ; )

One thought. I allowed 2005 to convert my application from 2003 to 2005.
When I did this with a project from 2002 to 2003 it turned out the
conversion was not entirely successful, and 3 weeks later I ran into a bug
that could only be fixed by opening up a new 2003 project and copying the
source over form the previous project (it kept telling me I was using an
out-dated version in the Linker, but the interesting part is that this
warning only started happening weeks after I did the conversion, during
which time I did EXTENSIVE changes and additions to the code). Is it
possible the 2003 to 2005 conversion also has problems?

[==P==]

"RalphTheExpert" <ra****@dos32.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
我的猜测是控制台屏幕出现,因为你已经指定链接器选项子系统是控制台而不是windows。

如果程序是控制台,那么envirnoment要简单得多,而且在掷骰子和捕获物之间可能会有更少的dll。

我依稀记得在VC 6中遇到同样的问题。如果我的记忆是正确的话尝试从一个消息内部进行抛出是一件很糟糕的事情。

我对/子系统中MC ++的内部知识相当少:windows
尽管如此,我肯定想知道在消息处理程序中从
进行抛出是否合法WinMain的出路。
My guess is that the console screen comes up because you have specified
that the linker option, subsystem, is console rather than than windows.

If the program is console then the envirnoment is much simpler and
there are likely far fewer dlls between a throw and the catch.
I vaguely remember haveing the same problem in VC 6. If my memory is
correct, it was bad to attempt to do a throw from inside of a message
pump to outside of one.
I know fairly little of the internals of MC++ in a /subsystem:windows
environment. I''m not even sure if there is a message pump.

Nonetheless, I''d sure like to know if it is legal to do a throw from
inside a message handler all the way out to WinMain.



这篇关于未处理的异常 - 在调试器和非调试器下不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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