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

#include <iostream>

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

class MyError{
public:
	//Constructor
	MyError(const char* pStr = "There was an error.") : pMessage(pStr){};
	//Error message string
	virtual const char* MyError::What()const
	{ 
		return pMessage; 
	}
	//Destructor
	MyError::~MyError(){}
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 << endl << "Error: " << typeid(e).name() << endl << e.What() << endl;
	}

	system("pause");
	return 0;
}
