473,406 Members | 2,956 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Mysterious copy of exception object (C++)

Hello,

I'm using VC6.0 SP6 on Win2K machine. I have strange behaviour of
exception handling mechanism. Here's small example that exposes the
issue:

-------
class X
{
public:
X()
{ _tprintf(_T("X::X(); 0x%p\n"), this); }

X(const X& other)
{ _tprintf(_T("copy; 0x%p = 0x%p\n"), this, &other); }

~X()
{ _tprintf(_T("~X::X(); 0x%p\n"), this); }
};

int _tmain(int argc, _TCHAR* argv[])
{
try
{
_putts(_T("before"));
throw X();
}
catch(X& x)
{
_putts(_T("catch"));
}

_putts(_T("after"));

return 0;
}
-------

It produces correct output:
-------
before
X::X(); 0x0012FF68
catch
~X::X(); 0x0012FF68
after
-------

Now, if I remove copy constructor and build and run it, then output
is:
-------
before
X::X(); 0x0012FF64
~X::X(); 0x0012FF64
catch
~X::X(); 0x0012FF68
after
-------

As you can see default copy constructor was created by compiler and
actually called. My question is: Why copy constructor is not called
when I explicitly provide it, but called when auto generated by
compiler?

Thanks in advance
Alex
Jul 22 '05 #1
0 970

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

42
by: Edward Diener | last post by:
Coming from the C++ world I can not understand the reason why copy constructors are not used in the .NET framework. A copy constructor creates an object from a copy of another object of the same...
1
by: Jesse McGrew | last post by:
Hi, I'm trying to create an AppDomain and use it to load an assembly with reduced permissions (e.g. the "Internet" named permission set). Unfortunately, the permissions seem to be reduced *too*...
12
by: Andrew Schepler | last post by:
When compiled with Visual C++ .NET 2003 (only), the program below aborts as though no matching catch clause is present. If the copy constructor of A is made public, it successfully catches the...
13
by: Max | last post by:
Hi There! I'm having a mysterious error right after I login using Forms Authentication in my ASP.NET app. Below is the error... Exception Details: System.NullReferenceException: Object...
0
by: ryan groth | last post by:
Every three or four compiles I get a TypeLoadException everytime I run a web application on the same one or two dlls. The exception information is vauge, no file errors, no permission errors, no...
4
by: Wayne Wengert | last post by:
I have an aspx page on which I am trying to copy the contents of a textbox to the client clipboard when the users clicks a button. The button code is as follows:...
8
by: joel.winteregg | last post by:
Hi all, I "learnt" C++ a few years ago and then i have been using C for a couple of month and i'm now trying to get back to the ++ world (but with some troubles...). I have some problem to...
13
by: JD | last post by:
Hi, My associate has written a copy constructor for a class. Now I need to add an operator = to the class. Is there a way to do it without change her code (copy constructor) at all? Your help...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.