gpt4 book ai didi

c++ - 如何捕获 WndProc() 函数中定义的静态对象的异常?

转载 作者:可可西里 更新时间:2023-11-01 09:30:51 26 4
gpt4 key购买 nike

下面的伪代码中,WndProc() 是 Win32 API 中的标准消息处理函数,如何捕获静态对象 a 抛出的异常?

class A
{
public:
class Exception{};
A() throw(Exception) { ... }
};

LRESULT CALLBACK WndProc (HWND hwnd, UINT message, UINT wParam, LONG lParam)
{
static A a;

switch( message )
{
case WM_CREATE:

...

break;

...

default:

return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}

最佳答案

非 POD 结构的函数级静态在第一次调用函数时初始化,您可以将代码块包装在 try and catch 中,并像任何正常情况一样捕获异常

关于c++ - 如何捕获 WndProc() 函数中定义的静态对象的异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10299024/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com