1

In Visual C++ 2008, I want to "catch" an exception generated as shown here:

try {
    int foo = 20;
    ::fgetpos(0, (fpos_t*)&foo);
}
//...

Here are adjustments I've made to attempt a successful catch:

  1. SEH is activated (/eha)
  2. I've added a catch(...)
  3. I've added a _set_se_translator vector.
  4. I've added/adjusted to SEH syntax: __try / __except(EXCEPTION_EXECUTE_HANDLER)

In short, I've tried "everything in the book" and I still can't catch the exception. If I replace the call to ::fgetpos with int hey = foo / 0 then suddenly all of the above techniques work as expected. So the exception I'm dealing with from ::fgetpos is somehow "extra special."

Can someone explain why this ::fgetpos error seems uncatchable, and how to work around it?

update When executed in the VS IDE, the output window doesn't name an exception. All it says is this:

Microsoft Visual Studio C Runtime Library has detected a fatal error in MyProgram.exe.

Not very helpful. When I run the console app from the command line, I get a crash dialogue. The "problem details" section of the dialogue includes this information:

Problem Event Name: BEX
Exception Offset:0002fd30
Exception Code: c0000417
Exception Data: 00000000
Additional Information 1:69ad
Additional Information 2:69addfb19767b2221c8e3e7a5cd2f4ae
Additional Information 3:b1ff
Additional Information 4:b1ffca30cadddc78c19f19b6d150997f

4

2 回答 2

3

由于您的转储中的代码对应于STATUS_INVALID_CRUNTIME_PARAMETER,请尝试_set_invalid_parameter_handler

于 2011-02-19T23:23:50.787 回答
2

最有可能的是,运行时会为您捕获它并发出一个调试对话框,而不返回或传播异常——这是一个 CRT 调用,他们可能会在其中添加任何他们喜欢的异常捕获代码。在库函数中捕获硬件异常完全属于 Visual Studio 的权利,特别是如果您在 IDE 中或在调试模式下运行,则需要运行时。

当然,当你除以零时,这里就没有库调用来编写额外的捕获代码。

于 2011-02-19T22:55:54.597 回答