added exception handling code