Raise an exception if filename isn't valid