0

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)
3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by ithelp
0

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.

Edited by pecet: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.