Added proper exception handling, if there are not enough free resources to allocate...