728x90
반응형
#include <iostream>

/* Define function for Rule 3. *//*
void except(int a, int b)
{
	if (b == 0)
	{
		throw b;
	}
	std::cout << "Division result :" << a << " / " << b << " = " << a / b << std::endl;
}
*/

int main(void)
{
	int a;
	int b;

	std::cout << "Please enter the two interger: ";
	std::cin >> a >> b;
	
	/*======================================================================*/

	/* Common  *//*
	std::cout << "Division result :" << a << " / " << b << " = " << a / b << std::endl;
	*/

	/*======================================================================*/

	/* Rule 1. *//*
	if (b == 0)
		std::cout << "Divisior cannot be zero" << std::endl;
	else
		std::cout << "Division result :" << a << " / " << b << " = " << a / b << std::endl;
	*/

	/*======================================================================*/

	/* Rule 2. (Recommend) *//*
	try
	{
		if (b == 0)
		{
			throw b;
		}
		std::cout << "Division result :" << a << " / " << b << " = " << a / b << std::endl;
	}
	catch (int exception)
	{
		std::cout << "Occured exception : Divisior cannot be " << b << std::endl;
	}
	*/
	
	/*======================================================================*/

	/* Rule 3. (Using function) *//*
	try
	{
		except(a, b);
	}
	catch (int exception)
	{
		std::cout << "Occured exception : Divisior cannot be " << b << std::endl;
	}
	*/

	/*======================================================================*/

	return 0;
}
728x90
반응형

'Language > C & C++' 카테고리의 다른 글

[C++] Related to Reference  (0) 2022.10.17
[C] Related to Preprocessor  (0) 2022.10.17
Implement reference-based call-by-reference  (0) 2022.09.28
l-value and r-value  (0) 2022.09.27
Class  (0) 2022.09.26

+ Recent posts