c ++ try-except语句 [英] c++ try-except statement

查看:642
本文介绍了c ++ try-except语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了有关检测VMWare或虚拟PC的文章

http://www.codeproject.com/KB/system/VmDetect.aspx

,我看到他们使用某种try-except语句。

So我在MSDN中查找: http:/ /msdn.microsoft.com/en-us/library/s58ftw19%28v=vs.80%29.aspx

I came across this article about detecting VMWare or Virtual PC
http://www.codeproject.com/KB/system/VmDetect.aspx
and I saw that they use some kind of try-except statement.
So I looked it up in the MSDN: http://msdn.microsoft.com/en-us/library/s58ftw19%28v=vs.80%29.aspx

我不明白为什么我会使用try-except而不是好的旧try-catch。
它只是给我有关异常的额外信息吗?

如果是这样,我可以使用try-catch,当我使用附带的文章中的代码,对吗?

感谢:)

and I don't understand why would I use a try-except instead of the good old try-catch. does it just give me additional information about the exception?
If so, I can use a try-catch when I use the code from the attached article, right?
thanks :)

推荐答案

__ try / __except 尝试 / catch 种异常。您可以捕获硬件异常,如浮点违规,坏指针解引用等,而不是C ++异常。这被称为结构化异常处理或SEH,如果你知道在哪里查找,MSDN有很多。

__try/__except is a try/catch, for a different kind of exception. You can catch hardware exceptions like floating point violation, bad pointer de-reference, etc, and not C++ exceptions. This is referred to as Structured Exception Handling, or SEH, and MSDN has quite a bit on it if you know where to look.

在这种情况下,他们使用它检测无效指令。这是他们尝试执行x86不支持的指令,虚拟机使用它们。如果你在一个真正的CPU上运行,那么你会得到一个无效的指令异常,如果你在一个虚拟机上运行,​​你刚刚谈到它。

In this case, they're using it to detect invalid instructions. This is where they attempt to execute instructions that x86 doesn't support, and virtual machines use them. If you're running on a real CPU, then you will get an invalid instruction exception, and if you're running on a virtual machine, you just talked to it.

这篇关于c ++ try-except语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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