Microsoft KB Archive/141447

From BetaArchive Wiki
Knowledge Base


FIX: dbDao's CdbException Uses Private Constructor

Article ID: 141447

Article Last Modified on 10/2/2003



APPLIES TO

  • Microsoft Data Access Objects 3.0
  • Microsoft Data Access Objects 3.5
  • Microsoft Data Access Objects 3.51
  • Microsoft Data Access Objects 3.6



This article was previously published under Q141447

SYMPTOMS

It is difficult to explicitly throw a CdbException from the dbDAO class library. It is possible, depending on how the exception class is thrown, to generate this error:

C2248: 'CdbException::CdbException' : cannot access private member declared in class 'CdbException'

CAUSE

This is because the constructor for the class is implicitly private. It does not inherit, nor are any classes inherited from CdbException, and it does not define any friends for the class.

The dbDao classes, however, are successfully able to throw the exception, but only because of another bug within the Visual C++ 4.0 compiler that allows you to throw a temporary instance of a class with only a private constructor.

RESOLUTION

The error is generated if you declare an instance of CdbException and then attempt to throw it.

   HRESULT hr;
   CdbException myException( hr );
   throw myException;          // Generates error C2248
                

However, you can successfully throw the instance if you throw a temporary instance of CdbException.

   HRESULT hr;
   throw CdbException( hr );
                

Now it is possible to catch this exception using C++ exception handling.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ 32- bit Edition version 4.1.


Additional query words: kbVC400bug 3.00 4.00 4.10 vcfixlist410

Keywords: kbbug kbfix kbdatabase kbcode KB141447