应用程序定义的异常

时间:2012-04-10 11:10:03

标签: c++ c++builder

有人可以解释一下C ++ Builder XE中以下“调试器错误通知”的含义:

"Project ... faulted with message: 'application-defined exception (code 0x0eefface) at 0x755ad36f. Process Stopped. Use Step or Run to continue."

只有在我需要抛出异常时才会发生 - 调用throw会引发此错误。 我找不到有关此问题的任何信息。

抛出异常:

#define MY_ERROR_CODE 0xE0000046

throw TMyTrouble(MY_ERROR_CODE, "My error message"); // calling of this raises the application-defined exception...

捕捉:

try{
Function(); // function that raises the exception TMyTrouble
}
catch(...){ // this catch should catch the exception but it doesn't
// do something
throw; // throw to upper layer
}

异常的定义:

class TMyTrouble{
      public:
        TMyTrouble(int errorCode = 0xFFFFFFFF, AnsiString errorMessage = "Unknown error") { FMessage = errorMessage; FCode = errorCode;}
        __property AnsiString Message = {read = FMessage};
        __property unsigned long Code = {read = FCode};

      private:
        unsigned long FCode;
        AnsiString FMessage;
    };

3 个答案:

答案 0 :(得分:1)

你所看到的是完全正常的行为。您所看到的被称为“第一次机会异常”消息。在应用程序看到异常之前,调试器正在报告该消息。消息中的文字显示了这一点:“Process Stopped。使用Step或Run继续”。只需执行消息所说的内容 - 只需按F9键,或按工具栏上的“运行”按钮继续执行,异常将传回应用程序,以便在try/catch块中进行正常处理。

答案 1 :(得分:0)

这不仅仅是调试者说的方式,“我只是注意到抛出异常,你想做什么?”

如果您不想在抛出异常时停止调试器,则可以进行设置。

如果您选择了contine,那么您的代码应该会捕获它。

答案 2 :(得分:0)

我向你们所有人道歉,问题出现在抛出声明之前:

byte value;
sscanf(buffer, "%02x", &value);

你能看到问题吗? sscanf函数返回该格式字符串"%02x"一个长值(4个字节),但我有一个字节变量value(1个字节) - 所以在某处写了3个字节和堆栈是什么原因导致了我的问题...

感谢您的帮助