CPlusPlusThings/practical_exercises/10_day_practice/day9/异常例子/3.cpp
2020-06-08 20:34:54 +08:00

19 lines
482 B
C++

#include<iostream>
using namespace std;
void temperature(int t)
{
try{
if(t==100) throw "It's at the boiling point.";
else if(t==0) throw "It reached the freezing point";
else cout<<"the temperature is OK..."<<endl;
}
catch(int x){cout<<"temperature="<<x<<endl;}
catch(char const*s){cout<<s<<endl;}
}
int main(){
temperature(0); //L1
temperature(10); //L2
temperature(100); //L3
system("pause");
return 0;
}