pr25002.cpp
来自「c++编程宝典源码及Quincy99编译器 是《标准C++编程宝典》电子工业出」· C++ 代码 · 共 57 行
CPP
57 行
////////////////////////////////////////
// File Name: pr25002.cpp
////////////////////////////////////////
#include <iostream>
// Function prototypes.
void foo();
// Exception class declarations.
class Bummer {};
class Dumber {};
////////////////////////////////////////
// The main() function.
////////////////////////////////////////
int main()
{
// The try block.
try
{
std::cout << "calling foo" << std::endl;
foo();
std::cout << "return from foo" << std::endl;
}
// Catch exception handler.
catch(Bummer)
{
// Error-handling code.
std::cout << "catching Bummer" << std::endl;
}
catch(Dumber)
{
// Error-handling code.
std::cout << "catching Dumber" << std::endl;
}
std::cout << "done" << std::endl;
return 0;
}
////////////////////////////////////////
// Program function.
////////////////////////////////////////
void foo()
{
int error = 1;
// C++ statements to do stuff...
if (error)
{
std::cout << "throwing Dumber" << std::endl;
throw Dumber();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?