//异常处理的简单应用。 #include <iostream> using namespace std; int Div(int a, int b) { if(b == 0) { throw b; } cout<<"OK"<<endl; return a/b; } void main() { int a,b; cout<<"请输入两个整数:"; cin>>a>>b; try { cout<<Div(a,b)<<endl; } catch(int) { cout<<"错误,除数不能为0!"<<endl; } } <img src="http://img.blog.csdn.net/20150514234522101?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZG91ZG91d2ExMjM0/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /> <img src="http://img.blog.csdn.net/20150514234623351?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZG91ZG91d2ExMjM0/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
原文地址:http://blog.csdn.net/doudouwa1234/article/details/45728411