title: How do I get a variable out of a try/catch block?
body: <p>I've been trying to get this right for 2 days and am about ready to throw something .....</p>
  
  <p>I have a JSONArray which I'm processing in a try/catch block but it doesn't seem to pass the variable out at the end.</p>
  
  <p>My code:</p>
  
  <pre><code>try{
      //Get the element that holds the results ( JSONArray )
      JSONArray  getresults = json.getJSONArray("results");
      //Loop the Array
      for(int i=0;i &lt; getresults.length();i++){                       
          HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
          JSONObject e = getresults.getJSONObject(i);
          totalpass = e.getJSONObject(i).getString("ftotalpass");                         
      }                              
  
  } catch(JSONException e)        {
      Log.e("log_tag", "Error parsing data "+e.toString());                                       
  }
  </code></pre>
  
  <p>I've tried all manor of declaring the variable before, in, after the try/catch block but I just cannot get it to pass to the rest of my code.</p>
  
  <p>What am I doing wrong?</p>