Define the exception class MemoryAllocationExceptand then revise the definition of the method pushin the class LinkedStackso that it throws this exception if it cannot allocate a new node.

What will be an ideal response?

```
#include
#include
classMemoryAllocationExcept: public exception
{
public:
MemoryAllocationExcept(conststd::string& message = "") :
exception("The operation push cannot allocate memory: " +
message.c_str())
{
} // end constructor
}; // end MemoryAllocationExcept
template
bool LinkedStack::push(const ItemType& newItem)
throw(MemoryAllocationExcept )
{
try
{
Node* newTopNode = new Node(newItem, topPtr);
topPtr = newTopNode;
}
catch (bad_alloc e)
{
throw MemoryAllocationExcept("MemoryAllocationExcept : " +
"push() cannot allocate memory.");
} // end try/catch
return true;
} // end push

```

Computer Science & Information Technology

You might also like to view...

A back-end database file contains _________

Fill in the blank(s) with correct word

Computer Science & Information Technology

Word cannot be setup to always save the document in an older format, this action must be done individually for every document

Indicate whether the statement is true or false

Computer Science & Information Technology