Copy assignment definition

Pages: 123
We do the memory checking at the application level so that things like vector classes can just assume that new will work.
Where is that point exactly please? I'm used to using Qt for GUI programming. Where in the project should I use that memory checking?
Where is that point exactly please?


You don't need to do memory checking for new anywhere. You are just designing the vector class. The user of your vector class will be doing the memory checking if new fails. Your class can just assume that it works. If it doesn't that's the problem for the user of your class to deal with.

Note, the user of your class could be you. The point is, there is no need to check if new fails within the vector class.
Thanks for your help but I suppose that's too much huge and complicated!!Do you think it's commonly used?


Its used in programs/projects that care/rely about/on performance, that's for sure, there are bunch of such open source projects I've seen. In most cases having their own implementation.

I honestly didn't know for standard implementation which is quite simple, but I was reading the cpp reference yesterday and stumbled upon memory_resource library, recalled your thread and thought to share my discovery with you.

As for complicated, you can relax for next one year or so I guess, because after running a test, it looks like it's not fully implemented yet in msvc.
Thanks for remembering my issue and for your help too.
I surfed the Web for a good while to reach a result how to handle exceptions properly but couldn't find such a thing. Probably, as said above, it's the customer's job to say how their program reacts to a kind of exception and how to another. To me, the first and normal choice is to leave a message and abort the program making the resources released and the user notified of the problem occurred this way. But not sure yet.
Last edited on
It is a question of who can and should handle the error.

Is it "network server seems busy, I will spin hourglass icon for 5 min and try again"
or "network server seems busy, I will tell the user"
or "network server seems busy, I let calling code decide"
or "network server seems busy, lets exit(42)"
or "mouse has moved, Windows has to be reinstalled from scratch".
OK, for a more basic scenario, our Vector, which is more common for a bad_alloc or invalid_argument exception, please? To recover from the exception and continue the program (I don't know how), or to terminate the program by abort() for instance, and leaving a message for the user to see?
Last edited on
OK, for a more basic scenario, our Vector, which is more common for a bad_alloc or invalid_argument exception, please? To recover from the exception and continue the program (I don't know how), or to terminate the program by abort() for instance, and leaving a message for the user to see?


It depends. What is the program?

If it's a telephone switch, you probably want to recover from the exception and continue the program. Nobody wants a telephone switch rebooting while it is carrying thousands of active calls.

If it's a simple program as a proof-of-concept demo to be run under controlled conditions, you can probably just let the program abort and run it again.

There is no "more common". Exception handling merely notifies the calling program that something happened, and the program can decided what to do about it. The programmer determines how robust the system needs to be and what steps are required when encountering an exception.

And sometimes the program is initially written to just abort when an exception occurs, but during later development the program is hardened to gracefully handle more exceptions. It all depends on needs and the current stage in the life cycle of the program.
Thanks, got it.
My last question on this thread I guess would be this: If we want to recover from such exceptions (bad_alloc and invalid_argument), how to do this, please? @mailbor suggested a way, which is really very complex, and fortunately not working for the time being. :) :) Hhhh
Is there any better solution, please?
Last edited on
As I mentioned before, recovering from a bad alloc is nearly impossible.

Recovering from invalid_argument within the vector class is completely impossible. It indicates a programming error or bad input. There's no way for the vector class to know how to fix it.

Personally, I think you're over-thinking all this. Vector is a utility class. It doesn't know anything about the application that calls it. The best it can do in error conditions is (1) keep the Vector in some consistent state and (2) report the error to the caller.
If we want to recover from such exceptions (bad_alloc and invalid_argument), how to do this, please?


Again, it depends.

What should the program do if it fails to allocate? If you are that close to exhausting your memory, you might not be able to do anything anyway, so simply logging a message to the user (if you are able to do it) and aborting might be all you can do.

What are invalid arguments? How would they get passed in? If they do get passed in, what do you want the program to do?

Handling exceptions might be as simple as having the calling function return false. It might be to pass the exception all the way up to the top and let the program abort.

This is why you get paid the big bucks as a programmer. You get to decide how to handle an exception. It's not trivial, but it should return something consistent. Set the states of all associated objects and variables to something that makes sense, and return from the function.

There is no cookie cutter solution to handling exceptions.
Thanks to all so much. :)
Topic archived. No new replies allowed.
Pages: 123