c++ - 如何替换多行 cpp 代码?
问题描述
我有一个带有多个 catch 语句的 try-catch。捕获语句大约有 30 行代码。许多函数具有相同的 catch 语句。我想用一行代码(将在某处定义,如宏)替换它们。这对 c++ / Microsoft Visual Studio 是否可行?
try {...}
<INSERT SINGLE LINE OF CODE HERE>
代替:
try {...}
catch (HRESULT hr) {...}
catch (std::exception & e) {...}
catch (LPCWSTR e) {...}
catch (...) {...}
谢谢你。
解决方案
函数有什么问题?
void common_handler() { /* handle common */ }
try {...}
catch (HRESULT hr)
{
common_handler();
// handle specific
}
catch (std::exception & e)
{
common_handler();
// handle specific
}
catch (LPCWSTR e)
{
common_handler();
// handle specific
}
catch (...)
{
common_handler();
// handle specific
}
推荐阅读
- unity3d - VS2015中的“已导入具有相同标识的多个程序集”,带有Unity生成的csproj
- javascript - javascript regex 删除空格和一个字母
- java - LDAP 引用前置库
- awk - 使用 awk 基于公共行合并两个文本文件
- zeromq - ZeroMQ:到 DEALER 套接字代理的 STREAM 套接字
- javascript - 如何在使用 Jquery 设置时间间隔后关闭 Bootstrap 模式窗口?
- python - 具有多个模型的 CreateView 和 ModelForm
- ms-access - SetFocus 到子表单数据表视图中的控件,其中复选框 = True
- angular - angular 5,keycloak-angular end 错误
- google-apps-script - 从数组创建多个项目