I'm having a problem implementing the complexdivbyzero exception handler. It is supposed to be triggered if the user inputs a complex number with both the real and imaginary part being zero. Any help would be appreciated.

class ComplexDivByZero{};
complexType complexType::operator/ (const complexType& otherComplex) const throw (ComplexDivByZero)
{
    complexType temp;
    if (temp.realPart == 0 && temp.imaginaryPart == 0)
    {
        throw ComplexDivByZero();
    }
    else
    { 
              //calculation
    }
}

In main:

try
        {
            cout << num1 << " / " << num2 << " = " << num1 / num2 << endl;
        }
            catch(ComplexDivByZero)
        {
            cout << "Caught an exception!" << endl;
        }

Warning:

warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow)

I haven't seen default contructor for your class complexType, but I guess, that in line

complexType temp;

You have uninitialized variable (object). Maybe that's the problem.

You have defined an empty class .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.