Error handing in detect method