title: Using try-catch -- Skipping try
body: <p>I'm trying to write a code that I can try a JSON object and if it's the wrong format inform the user somehow.</p>
  
  <p>The code is : </p>
  
  <pre><code> public boolean sjekkSporingsNummer (JSONObject object){       //object is passed correct
      Boolean riktigSporing = null; 
      riktigSporing = true;                                     //riktig sporing is set to true
      //if its true the json is correct
      try {
      JSONArray consignmentSet = object.getJSONArray("consignmentSet");
      JSONObject object1 = consignmentSet.getJSONObject(0);
      riktigSporing = true;
      }catch (Exception e){                                 //skips straigt to here
          e.printStackTrace();
          riktigSporing = false;
      }
      return riktigSporing;
  </code></pre>
  
  <p>After if failes with : </p>
  
  <pre><code>07-31 12:34:07.243  15479-15479/com.example.posten E/AndroidRuntime: FATAL EXCEPTION: main
      java.lang.NullPointerException
  </code></pre>
  
  <p>What seems wierd to me is that my app skips the try and goes straight to the return statement.</p>
  
  <p>I would like it to try and of it failes set "riktigSporing" to false.</p>
  
  <p>What am I doing wrong? </p>