Throwing exception when no memory could be allocated

As title says.