add exception handling code for OOM case