I want to implemet linked list in c++ ,while adding new node I dynamicly allocate it, if some allocation fails I would like my program to stop the execution.

After the "new Node" fails the exception is thrown so do I have to call the destructor explicitly in the exception handler. how can I deal with this situation in order to prevent memory leak?

If your linked list is a class and you've written a proper destructor, the list should be destroyed correctly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.