Fixed infinite recursion when an exception has a previous exception.

Was supposed to be fixed in ee5962b52bc but was lost while resolving conflicts in cherry-picking.