PROGRAMMING LANGUAGE/C++
c++예외처리
JC0
2021. 12. 1. 21:51
#include <iostream>
using namespace std;
void divide(int a, int b)
{
int c, d;
string str1 = "qwert";
if (b == 0) throw str1;
c = a / b; cout << "몫은 -> " << c << endl;
d = a % b; cout << "나머지 -> " << d << endl;
cout << endl;
}
void main()
{
try
{
divide(10, 2);
divide(10, 0);
divide(10, 4);
}
catch (int ex)
{
cout << ex << "예외발생" << endl;
}
catch (char* str)
{
cout << str << "str예외발생" << endl;
}
cout << "\n예외가 발생하더라도 정상 종료된다." << endl;
}