error checking for typecasts