Archived

This topic is now archived and is closed to further replies.

AlekM

Problem handling exceptions using object instance and reference

Recommended Posts

Hi, I am wondering if anyone else knows of any issue with Visual C++ Service Pack 4 with handling exceptions using an object instance or an object reference. The only way I have been able to handle my class exceptions is by throwing a pointer It worked with an older service pack, now the code works, doesn't give a compilation error, but the data within the class is gone. Any help is greatly appreciated. Example:
        

void CSomeOtherClass::Method()
{
    throw CException("Exception","User Defined Message");

    //I've also tried calling the throw from within the exception

    //class liket his

    CException exception("Exception","User Defined Message");
    exception.Raise();

    //Raise() would simple throw *this
}

void CSomeOtherClassHandlingAnExcpetion::Method()
{
    try
    {
        CSomeOtherClass::Method();
    }
    catch( CException& refException )
    {
        refException.Report();
    }

    //I also tried to handle the exception by handling it as an object

    //catch( CException objException )
}
        
Yes, my CException class has valid copy constructors and overloaded assignment operators, so the above should work. thanks Alek Edited by - alekm on 11/1/00 2:07:45 PM

Share this post


Link to post
Share on other sites
I do this all the time. Are you sure you have exceptions enabled in your project->settings->C/C++->C++ Language menu?

Here''s a test using standard exceptions that should do the trick for you:

    
#include <exception>
#include <iostream>
using namespace std;
int main ()
{
try
{
throw runtime_error ("testing exception");
}
catch (exception& x)
{
cout << "Caught exception: " << x.what () << endl;
}
return 0;
}

Share this post


Link to post
Share on other sites