title: Android Java Exceptions - How do they work when thrown manually?
body: <p>I am interested in how exceptions in Android work when trown manually.
  I tried to make an app where you can push a button and a random exception would popup.
  Here I noticed something strange. When for instance, I throw an ArrayIndexOutOfBoundsException, I get an IlligalStateException.</p>
  
  <p>Function that generates exception:</p>
  
  <pre><code>public void GenerateRandomException(View view)
  {
      Random rand = new Random();
      int random = rand.nextInt(5);
  
      switch(random)
      {
          case 0:
              throw new ArrayIndexOutOfBoundsException("An ArrayIndexOutOfBoundsException occured!");
          case 1:
              throw new RuntimeException("A RuntimeException occured!");
          case 2:
              throw new NullPointerException("An NullPointerException occured!");
          case 3:
              throw new IllegalThreadStateException("An IllegalThreadStateException occured!");
          case 4:
              throw new IllegalArgumentException("An IllegalArgumentException occured!");
          default:
              break;
      }
  }
  </code></pre>
  
  <p>Stacktrace:</p>
  
  <pre><code>FATAL EXCEPTION: main
  java.lang.IllegalStateException: Could not execute method of the activity
      at android.view.View$1.onClick(View.java:3838)
      at android.view.View.performClick(View.java:4475)
      at android.view.View$PerformClick.run(View.java:18786)
      at android.os.Handler.handleCallback(Handler.java:730)
      at android.os.Handler.dispatchMessage(Handler.java:92)
      at android.os.Looper.loop(Looper.java:176)
      at android.app.ActivityThread.main(ActivityThread.java:5419)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:525)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
      at dalvik.system.NativeStart.main(Native Method)
  Caused by: java.lang.reflect.InvocationTargetException
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:525)
      at android.view.View$1.onClick(View.java:3833)
      ... 11 more
  Caused by: java.lang.ArrayIndexOutOfBoundsException: An ArrayIndexOutOfBoundsException occured!
      at gamebugtracker.lib.MainActivity.GenerateRandomException(MainActivity.java:78)
      ... 14 more
  </code></pre>
  
  <p>As seen in the stacktrace, it says there is an IlligalStateEception, caused by the ArrayIndexOutOfBoundsException.<br>
  I find this strange, shouldn't the ArrayIndexOutOfBoundsException, be the top exception?
  Or did I broke my own code?</p>