redux of an exception fix

Redux of #2544: remove an early return; fix the exception via an additional check in the if statement.

@ussuri