Bug in exception handling logic