Handling all cases of memory errors gracefully.