Handling exceptions and random events