在托管代码中捕获非托管异常,而不是在releasebuild中工作 [英] catching unmanaged exceptions in managed code, not working in releasebuild

查看:74
本文介绍了在托管代码中捕获非托管异常,而不是在releasebuild中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我遇到了非托管异常的问题。在调试版本中它可以工作

可以很好地捕获来自其他dll的非托管c ++异常


//托管代码:

try

{

//表单加载非托管dll,其中非托管异常//获取

抛出

应用程序::运行(新Form1());

} catch(std :: exception& e)

{

//抓住工作debud build,在发布版本中构建一个SEHException

//被抛出

}

但是在发布版本中,相同的c ++异常并没有被捕获但是我

从.net框架获取SEHException。知道是什么导致这个问题吗?
问题?我已经检查了构建选项,并且在发布版本中启用了c ++异常

,所以问题必须在其他地方... ...


最好的问候,


Vasco Lohrenscheit

解决方案

" Vasco Lohrenscheit" < VA ********* @ web.de>在留言中写道

news:ce ********** @ online.de ...



我有一个非托管异常的问题。在调试版本中,它可以很好地捕获来自其他dll的非托管c ++异常。
//托管代码:
尝试
{
//表单加载非托管dll,其中出现非托管异常//得到
Application :: Run(new Form1());
} catch(std :: exception& e)
{
//在debud构建中捕获工作,在发布版本中构建SEHException
//被抛出
}
但是在发布版本中,相同的c ++异常没有被捕获但是我<从.net框架获取SEHException。知道是什么原因导致这个问题吗?我已经检查了构建选项,并且在发布版本中也启用了c ++异常,所以问题必须放在其他地方...




我''更让你感到惊讶的是你得到了std异常 - 无论如何我们所有的非托管

断言都变成了SEHExceptions。尝试一下第一个来自

异常的地方,以及调试和发布之间

编译器和链接器设置的任何差异。


Steve


Steve McLellan写道:


Vasco Lohrenscheit < VA ********* @ web.de>在消息中写道
新闻:ce ********** @ online.de ...



我有一个问题非管理异常。在调试版本中,它可以很好地捕获来自其他dll的非托管c ++异常。
//托管代码:
尝试
{
//表单加载非托管dll,其中出现非托管异常//得到
Application :: Run(new Form1());
} catch(std :: exception& e)
{
//在debud构建中捕获工作,在发布版本中构建SEHException
//被抛出
}
但是在发布版本中,相同的c ++异常没有被捕获但是我<从.net框架获取SEHException。知道是什么原因导致这个问题吗?我已经检查了构建选项,并且在发布版本中也启用了c ++异常,所以问题必须放在其他地方...



我更让你感到惊讶得到std异常 - 无论如何我们所有的非托管
断言都变成了SEHExceptions。尝试首先解决
异常的来源,以及Debug和Release之间的
编译器和链接器设置的任何差异。

Steve




这也是我要回应的内容,但并不是因为我没有确定答案。

明确答案。 />

听起来你的调试版本行为不正确,版本正在运行

应该如此。


Julie写道:


这也是我要回应的内容,但并不是因为我没有确定的答案。

听起来你的调试版本行为不正确,并且版本正在运行
应该这样。



这里有人有明确的答案吗? br />

因此托管代码中无法捕获非托管异常?好吧,多数民众赞成

非常糟糕。这会随着标准化的c ++ / CLI绑定而改变吗?

是否有任何可能从SEHException中提取原始的非托管异常和

类型?


如何处理非托管异常托管代码中的例外情况?

最好的问候,

Vasco Lohrenscheit


Hi,

I have a Problem with unmanaged exception. In the debug build it works
fine to catch unmanaged c++ exceptions from other dlls with

//managed code:
try
{
//the form loads unmanaged dlls out of which unmanaged exception //get
thrown
Application::Run(new Form1());
} catch (std::exception& e)
{
//catching work in debud build, in release build a SEHException
//gets thrown
}
But with the release build the same c++ exceptions are not catched but I
get a SEHException from the .net framework. Any idea what can cause this
Problem? I already checked build options and c++ exceptions are enabled
in the release build too, so the problem has to lie somewhere else...

best regards,

Vasco Lohrenscheit

解决方案

"Vasco Lohrenscheit" <va*********@web.de> wrote in message
news:ce**********@online.de...

Hi,

I have a Problem with unmanaged exception. In the debug build it works
fine to catch unmanaged c++ exceptions from other dlls with

//managed code:
try
{
//the form loads unmanaged dlls out of which unmanaged exception //get
thrown
Application::Run(new Form1());
} catch (std::exception& e)
{
//catching work in debud build, in release build a SEHException
//gets thrown
}
But with the release build the same c++ exceptions are not catched but I
get a SEHException from the .net framework. Any idea what can cause this
Problem? I already checked build options and c++ exceptions are enabled
in the release build too, so the problem has to lie somewhere else...



I''m more surprised you get the std exception at all - all our unmanaged
assertions get turned into SEHExceptions anyway. Try working out where the
exception''s coming from in the first place, and any differences in the
compiler and linker settings between Debug and Release.

Steve


Steve McLellan wrote:


"Vasco Lohrenscheit" <va*********@web.de> wrote in message
news:ce**********@online.de...

Hi,

I have a Problem with unmanaged exception. In the debug build it works
fine to catch unmanaged c++ exceptions from other dlls with

//managed code:
try
{
//the form loads unmanaged dlls out of which unmanaged exception //get
thrown
Application::Run(new Form1());
} catch (std::exception& e)
{
//catching work in debud build, in release build a SEHException
//gets thrown
}
But with the release build the same c++ exceptions are not catched but I
get a SEHException from the .net framework. Any idea what can cause this
Problem? I already checked build options and c++ exceptions are enabled
in the release build too, so the problem has to lie somewhere else...



I''m more surprised you get the std exception at all - all our unmanaged
assertions get turned into SEHExceptions anyway. Try working out where the
exception''s coming from in the first place, and any differences in the
compiler and linker settings between Debug and Release.

Steve



That is what I was going to respond as well, but didn''t because I didn''t have a
definitive answer.

Sounds like your debug build is behaving incorrectly, and release is operating
as it should.


Julie wrote:


That is what I was going to respond as well, but didn''t because I didn''t have a
definitive answer.

Sounds like your debug build is behaving incorrectly, and release is operating
as it should.


Does anybody has a definitive answer here?

So unmanaged exception can''t be catched in managed code? Well, thats
really bad. Will this change with the standardised c++/CLI binding? Are
there any possibilieties to extract the original unmanaged exception and
its type from the SEHException?

How do you handle unmanaged exceptions in managed code?
best regards,

Vasco Lohrenscheit


这篇关于在托管代码中捕获非托管异常,而不是在releasebuild中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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