Handles exceptions.