CPlusPlusThings/practical_exercises/10_day_practice/day9/异常例子/3.cpp
Light-City a4d828bb4c update
2020-04-06 00:57:02 +08:00

19 lines
439 B
C++

#include<iostream>
using namespace std;
void temperature(int t)
{
try{
if(t==100) throw "沸点!";
else if(t==0) throw "冰点!";
else cout<<"the temperature is OK..."<<endl;
}
catch(int x){cout<<"temperatore="<<x<<endl;}
catch(char const*s){cout<<s<<endl;}
}
int main(){
temperature(0); //L1
temperature(10); //L2
temperature(100); //L3
system("pause");
return 0;
}