63 - More Exceptions Examples

#include 
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)