How about putting this into a separate function to be called only when the error actually occurs.