Tuesday, June 4, 2013

Contoh Program Exception Handling C++ (3)

#include<iostream>
using namespace std;
template<class T>void LEMPAR(T X){
try{
if(X){
throw X;
}
}
catch(int E1){
cout<<"Menangkap ekspesi dengan tipe data int, yaitu : ";

cout<<E1<<endl;
}
catch(double E2){
cout<<"menangkap ekspesi dengan tipe data double, yaitu : ";
cout<<E2<<endl;
}
catch(char E3){
cout<<"Menangkap ekspesi dengan tipe data char, yaitu : ";
cout<<E3<<endl;
}
catch(char* E4){
cout<<"Menangkap ekspesi dengan tipe data char*, yaitu : ";
cout<<E4<<endl;
}
}
//Fungsi Utama
int main(){
LEMPAR(10);
LEMPAR(25.03);
LEMPAR('C');
LEMPAR("C++");
return 0;
}

No comments:

Post a Comment

Link