From: Eric Margheim on
I am getting a compiler error on the following bit of code

catch (CException e)

This code compiled fine in VS6. The VS2005 compiler says the following and
points to the following code in afx.h

error C2259: 'CException' : cannot instantiate abstract class
1> due to following members:
1> 'CException::~CException(void)' : is abstract

virtual ~CException() = 0;



Any thought on what I need to change here?


Thanks


From: Doug Harrison [MVP] on
On Tue, 13 Jun 2006 13:03:41 -0500, "Eric Margheim"
<NOSPAM***eric(a)prism-grp.com***NOSPAM> wrote:

>I am getting a compiler error on the following bit of code
>
>catch (CException e)
>
>This code compiled fine in VS6. The VS2005 compiler says the following and
>points to the following code in afx.h
>
>error C2259: 'CException' : cannot instantiate abstract class
>1> due to following members:
>1> 'CException::~CException(void)' : is abstract
>
>virtual ~CException() = 0;
>
>
>
>Any thought on what I need to change here?

You need to change this to:

catch (CException* e)
{
// Use e...
e->Delete(); // Do this if you don't rethrow
}

It may have compiled OK in VC6, but it never worked right, because MFC only
ever throws pointers to exceptions. So your code was never capable of
catching MFC exceptions thrown in the normal, correct way (well, normal and
correct for MFC, anyway).

--
Doug Harrison
Visual C++ MVP
From: Eric Margheim on
Cool thanks.

"Doug Harrison [MVP]" <dsh(a)mvps.org> wrote in message
news:ee4u82linn70t3uu5uehavn74ebo0fa4ok(a)4ax.com...
> On Tue, 13 Jun 2006 13:03:41 -0500, "Eric Margheim"
> <NOSPAM***eric(a)prism-grp.com***NOSPAM> wrote:
>
>>I am getting a compiler error on the following bit of code
>>
>>catch (CException e)
>>
>>This code compiled fine in VS6. The VS2005 compiler says the following
>>and
>>points to the following code in afx.h
>>
>>error C2259: 'CException' : cannot instantiate abstract class
>>1> due to following members:
>>1> 'CException::~CException(void)' : is abstract
>>
>>virtual ~CException() = 0;
>>
>>
>>
>>Any thought on what I need to change here?
>
> You need to change this to:
>
> catch (CException* e)
> {
> // Use e...
> e->Delete(); // Do this if you don't rethrow
> }
>
> It may have compiled OK in VC6, but it never worked right, because MFC
> only
> ever throws pointers to exceptions. So your code was never capable of
> catching MFC exceptions thrown in the normal, correct way (well, normal
> and
> correct for MFC, anyway).
>
> --
> Doug Harrison
> Visual C++ MVP


From: Eric Margheim on
>>virtual ~CException() = 0;
>>
>>
>>
>>Any thought on what I need to change here?
>
> You need to change this to:
>
> catch (CException* e)
> {
> // Use e...
> e->Delete(); // Do this if you don't rethrow
> }
>
> It may have compiled OK in VC6, but it never worked right, because MFC
> only
> ever throws pointers to exceptions. So your code was never capable of
> catching MFC exceptions thrown in the normal, correct way (well, normal
> and
> correct for MFC, anyway).
>

This is bad code too evidentally.

throw new CException(TRUE);






From: Doug Harrison [MVP] on
On Tue, 13 Jun 2006 15:10:26 -0500, "Eric Margheim"
<NOSPAM***eric(a)prism-grp.com***NOSPAM> wrote:

>This is bad code too evidentally.
>
>throw new CException(TRUE);

Since the class is now abstract, yes.

--
Doug Harrison
Visual C++ MVP
 |  Next  |  Last
Pages: 1 2
Prev: MFC examples
Next: creating a JPEG file