exit on error appropriately