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...

In a producer/consumer relationship with a single cell of shared memory, which of the following is true?

a. The consumer must run first. b. The producer must run first. c. The producer must run first or the consumer will have to wait. d. The consumer must run first or the producer will have to wait.

Computer Science & Information Technology

A(n) ____________________, like the one in the accompanying figure, is text and graphics printed at the top of each page in a document.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

In a search, by default Windows Vista uses a technique known as ________ ,which matches to a part of a word or phrase rather than to whole words

Fill in the blank(s) with correct word

Computer Science & Information Technology

Using the Brush panel, the ____ percentage specifies the ratio between the brush’s short and long axes.

a. pixel b. zero level c. axis d. roundness

Computer Science & Information Technology