FIX: dbDao's CdbException Uses Private Constructor (141447)
The information in this article applies to:
- The DAO SDK 3.0
- The DAO SDK 3.5
- The DAO SDK 3.51
- The DAO SDK 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.
Modification Type: | Major | Last Reviewed: | 10/2/2003 |
---|
Keywords: | kbbug kbcode kbDatabase kbfix KB141447 |
---|
|