FIX: dbDao's CdbException Uses Private Constructor

Last reviewed: September 19, 1997
Article ID: Q141447
3.00 WINDOWS NT kbprg kbcode kbbuglist kbfixlist

The information in this article applies to:

  • The DAO C++ Class Library included with: The DAO Software Development Kit (SDK), version 3.0

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 reference words: 3.00 4.00 4.10 vcbuglist400 vcfixlist410
KBCategory: kbprg kbcode kbbuglist kbfixlist
KBSubcategory: MfcDAO dbDao
Keywords : dbDao MfcDAO kbbuglist kbcode kbfixlist kbprg
Technology : kbMfc
Version : 3.00
Platform : NT WINDOWS
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 19, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.