什么更好使用,__try / __ except块或try / catch块? [英] What's better to use, a __try/__except block or a try / catch block?

查看:203
本文介绍了什么更好使用,__try / __ except块或try / catch块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道哪个是捕捉异常的更好的方法,我抛出:是一个__try / __except块还是一个try / catch块?

I'm wondering which is the better way to catch exceptions that I throw: is it a __try / __except block or a try / catch block?

我用C ++编写程序只能在Windows上使用,所以可移植性不是问题。

I'm writing in C++ and the program will only be used on Windows, so portability is not an issue.

谢谢!

推荐答案

c>尝试 / catch 阻止。

c $ c> __ try / __除了是用于捕获SEH(窗口生成的错误),不用于捕获一般异常。

As others have already answered, __try / __except is for catching SEH (windows generated errors) not for catching general exceptions.

最重要的是, __ try __ catch 可能无法运行C ++析构函数或正确展开堆栈

Most importantly, __try and __catch may not run C++ destructors or correctly unwind the stack when an exception is thrown.

除非在极少数情况下,否则不要尝试捕获SEH异常。

Except in rare cases, you should never try to catch SEH exceptions.

strong> EDIT:好了,我对此感兴趣(这是我一直告诉的),但是@Hans说,显然有一个编译器开关可以用来更改这个。我认为在 / EHa 上的文档是误导,或至少不完整,这里发生了什么。如果有人找到证明这个错误的确定的文档,我会很高兴地删除此答案。

Well, I was positive on this (it's what I've always been told), but @Hans says that apparently there is a compiler switch you can use to change this. I think the docs on /EHa are misleading, or at least incomplete, on what happens here. If someone finds definitive docs which prove this wrong, I'll happily remove this answer.

即使结果是假的,你仍然应该使用 try catch 只是因为它们是标准的,而 __ try __ except 不是。

Even if it turns out this is false, you should still use try and catch simply because they are standard, while __try and __except are not.

这篇关于什么更好使用,__try / __ except块或try / catch块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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