Throw proper exception when type casting function is not defined