title: How should I handle long exception handling code
body: <p>I am trying to make calls to an external API. I handle four or more exceptions for the call.</p>
  
  <p>If I make multiple calls, the code increases very quick. Should I be writing a wrapper for each such call which handles the exceptions and returns data?</p>
  
  <p>Here is an example of such <a href="http://devblog.springest.com/how-to-automatically-find-users-on-twitter/" rel="nofollow">code</a> (this is not mine).  The call to <code>user_search</code> is followed by the exception handling.</p>
  
  <p>Note: I am not using Rails</p>
  
  <pre><code>begin
  @twitter = Twitter.user_search(name)
  rescue Twitter::Unauthorized
    puts "Not authorized. Please check the Twitter credentials at the top of the script."
    break
  
  rescue Twitter::BadRequest =&gt; e
    puts "Hit rate limit. Continuing scraping at #{e.ratelimit_reset}"
    sleep e.retry_after
    retry
  
  rescue Exception =&gt; e
    puts "Something else went wrong:"
    puts e.message
  end
  </code></pre>
  
  <p>I've changed the title of the question.  I think the issue is more how to handle long exception handling code.  In the example code suppose I have multiple calls to the twitter API followed by exception handling, it seems like the exception handling code disrupts reading the code which does the actual work.</p>