Properly handle exceptions