美文网首页
63 - More Exceptions Examples

63 - More Exceptions Examples

作者: 社交帐号直接注册 | 来源:发表于2018-01-09 21:10 被阅读0次
#include <iostream>
using namespace std;

int main()
{
    try
    {
        int num1;
        cout << "enter first number: " << endl;
        cin >> num1;

        int num2;
        cout << "enter second number: " << endl;
        cin >> num2;

        if(num2==0)
        {
            throw 0;
        }

        cout << num1/num2 << endl;
    }
    catch(...)
    {
        cout << "you can't divide by 0" << endl;
    }
}

相关文章

网友评论

      本文标题:63 - More Exceptions Examples

      本文链接:https://www.haomeiwen.com/subject/dmggnxtx.html