Check if an error exists before accessing it