title: Rules for returning return type in case of Exception
body: <p>When I have a code like below, Compiler complains that "test() method must return a result of type int"</p>
  
  <pre><code>class ExecptionExample {
      public static void main(String[] args) {
          System.out.println("Result :"+test());
      }
      private static int test(){
          try{
              System.out.println("In try");
              throw new StackOverflowError("SOError");
          } catch(Exception e){
              System.out.println("In catch");
              //throw new ArrayIndexOutOfBoundsException();
          } finally{
              System.out.println("In finally");
              //throw new RuntimeException();
          }
          System.out.println("Outside try-catch");
          //return 0;
      }
  }
  </code></pre>
  
  <p>If I uncomment last line "return 0" then it compile and run but control never reaches at "return 0" and never prints "Outside try-catch"</p>
  
  <p>Consider code below,</p>
  
  <pre><code>class ExecptionExample {
      public static void main(String[] args) {
          System.out.println("Result :"+test());
      }
      private static int test(){
          try{
              System.out.println("In try");
              throw new StackOverflowError("SOError");
          } catch(Exception e){
              System.out.println("In catch");
              //throw new ArrayIndexOutOfBoundsException();
          } finally{
              System.out.println("In finally");
              throw new RuntimeException();
          }
          //System.out.println("Outside try-catch");
          //return 0;
      }
  }
  </code></pre>
  
  <p>In above code, compiler doesn't complain about "return int value required".</p>
  
  <p>So how things work? what is the rule that compiler checks for return required and not?</p>
  
  <p>I am thinking as finally block is always going to be executed (leaving few  conditions) and  <code>RuntimeException</code> is thrown in finally, so compiler doesn't require return int value? Please confirm my understanding.</p>
  
  <p>I am aware that <code>StackOverflowError</code> is not catch by <code>Exception</code>.</p>
  
  <p><strong>I just want to confirm one thing, in finally block it throws unchecked exception, is that the cause that compiler will not check return? because throwing unchecked exception from try block without finally block requires return and with finally block it doesn't requires return.</strong></p>