title: How do I test for exceptions in if-statements in python?
body: <p>i want to write a function to report the different results from another function
  there are some exceptions among these results but I cannot convert them into if statement</p>
  
  <p>example :</p>
  
  <blockquote>
    <p>if f(x) raise a ValueError, then my function has to return a string
    'Value' if f(x) raise a TypeError, then my function has to return a
    string 'Type</p>
  </blockquote>
  
  <p>But I don't know how to do this in Python. Can someone help me out.</p>
  
  <p>My Code is like this: -</p>
  
  <pre><code>def reporter(f,x):    
  
      if f(x) is ValueError():
          return 'Value'
      elif f(x) is E2OddException():
          return  'E2Odd'
      elif f(x) is E2Exception("New Yorker"):
          return 'E2'
      elif f(x) is None:
          return 'no problem'
      else:
          return 'generic'
  </code></pre>