Replace exit by exceptions.