title: Exception handling in Python and Praw
body: <p>I am having trouble with the following code:</p>
  
  <pre><code>import praw
  import argparse
  
  # argument handling was here
  
  def main():
      r = praw.Reddit(user_agent='Python Reddit Image Grabber v0.1')
      for i in range(len(args.subreddits)):
          try:
              r.get_subreddit(args.subreddits[i]) # test to see if the subreddit is valid
          except:
              print "Invalid subreddit"
          else:
              submissions = r.get_subreddit(args.subreddits[i]).get_hot(limit=100)
              print [str(x) for x in submissions]
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p><code>subreddit</code> names are taken as arguments to the program.</p>
  
  <p>When an invalid <code>args.subreddits</code> is passed to <code>get_subreddit</code>, it throws an exception which should be caught in the above code.</p>
  
  <p>When a valid <code>args.subreddit</code> name is given as an argument, the program runs fine.</p>
  
  <p>But when an invalid <code>args.subreddit</code> name is given, the exception is not thrown, and instead the following uncaught exception is outputted.</p>
  
  <pre><code>Traceback (most recent call last):
    File "./pyrig.py", line 33, in &lt;module&gt;
      main()
    File "./pyrig.py", line 30, in main
      print [str(x) for x in submissions]
    File "/usr/local/lib/python2.7/dist-packages/praw/__init__.py", line 434, in get_content
      page_data = self.request_json(url, params=params)
    File "/usr/local/lib/python2.7/dist-packages/praw/decorators.py", line 95, in wrapped
      return_value = function(reddit_session, *args, **kwargs)
    File "/usr/local/lib/python2.7/dist-packages/praw/__init__.py", line 469, in request_json
      response = self._request(url, params, data)
    File "/usr/local/lib/python2.7/dist-packages/praw/__init__.py", line 342, in _request
      response = handle_redirect()
    File "/usr/local/lib/python2.7/dist-packages/praw/__init__.py", line 316, in handle_redirect
      url = _raise_redirect_exceptions(response)
    File "/usr/local/lib/python2.7/dist-packages/praw/internal.py", line 165, in _raise_redirect_exceptions
      .format(subreddit))
  praw.errors.InvalidSubreddit: `soccersdsd` is not a valid subreddit
  </code></pre>
  
  <p>I can't tell what I am doing wrong. I have also tried rewriting the exception code as</p>
  
  <pre><code>except praw.errors.InvalidSubreddit:
  </code></pre>
  
  <p>which also does not work.</p>
  
  <p>EDIT: <a href="https://praw.readthedocs.org/en/latest/pages/code_overview.html#praw.errors.InvalidSubreddit" rel="nofollow">exception info for Praw can be found here</a></p>