fixing bad exception handling code