check the errors before doing the cast