// Throw an exception object with try and catch
// Date 19:55 01/11/2016
// By Ben a.k.a DreamVB

#include <iostream>

using namespace std;
using std::cout;
using std::endl;

class MyError{
public:
	MyError(const char* pStr = "There was an error.") : pMessage(pStr){};
	const char *What(){ return pMessage; }
private:
	const char *pMessage;
};

int main(int argc, char *argv[]){
	double a = 0;
	double b = 0;
	double r = 0;

	cout << "Enter first number  : ";
	cin >> a;
	cout << "Enter second number : ";
	cin >> b;

	try{
		//Check for zero
		if (b == 0){
			throw MyError("Cannot Divide By Zero.");
		}
		//Calc
		r = (a / b);
		//Show result
		cout << "a divided by b is : " << r << endl;
	}
	catch (MyError& e){
		cout << e.What() << endl;
	}

	system("pause");
	return 0;
}
