Added exception handling code.