add exception handling code for null return