title: Changing the default ValueError of file.index
body: <p>I was using <code>file.index</code> to search for a string in a file.</p>
  
  <pre><code>def IfStringExistsInFile(self,path,lineTextCheck):
      file = open(path).read()
      if file.index(lineTextCheck):
          print (lineTextCheck + " was found in: " + path)
      else:
          raise ValueError (lineTextCheck + " was NOT found in: " + path)
  </code></pre>
  
  <p>My issue is that if it does not find the string, it automatically raises a default ValueError and does not go into the "else" code which contains my custom ValueError:</p>
  
  <pre><code>ValueError: substring not found
  </code></pre>
  
  <p>Is there a way I could change that default ValueError?</p>
  
  <p>Currently, the only way I came up with was to wrap the sentence with "try except", like so:</p>
  
  <pre><code>def IfStringExistsInFile(self,path,lineTextCheck):
      file = open(path).read()
      try:
          if file.index(lineTextCheck):
              print (lineTextCheck + " was found in: " + path)
      except:
              raise ValueError(lineTextCheck + " was NOT found in: " + path)
  </code></pre>
  
  <p>Any better way would be greatly appreciated. Thank you in advance!</p>