📄 exceptions.cpp
字号:
#include <stdexcept>
#include <iostream>
void throwIf(bool inShouldThrow) throw (std::runtime_error)
{
if (inShouldThrow) {
throw std::runtime_error("Here's my exception");
}
}
int main(int argc, char** argv)
{
try {
throwIf(false); // doesn't throw
throwIf(true); // throws!
} catch (const std::runtime_error& exception) {
std::cerr << "Caught exception: " << exception.what() << std::endl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -