#include<iostream>
using namespace std;
void bigFunction(int bignum);
void smallFunction(int num);
void bigFunction(int bignum)
{
try {
smallFunction(bignum);
}
catch (const char* error_msg) {
cout << "catch small function error" << endl;
throw;
}
if (bignum < 50) {
throw "bignum < 50!";
}
else cout << "int big function: " << bignum << endl;
}
void smallFunction(int num)
{
if (num < 5) {
throw "num is smaller than 5!";
}
else cout << "in small function: " << num << endl;
}
int main()
{
int num = 3;
try {
bigFunction(num);
}
catch (const char* err_msg) {
cout << err_msg << endl;
}
return 0;
}
结果
catch small function error
num is smaller than 5!