Added a error handle function.