fix error handling not to itself raise an exception