#1261: Rearrange some error handling code.