Exception Handling Unreachable Code

Below is my code when I comment on operator-2, then it corresponds to fines, but when I uncomment, it gives a compile-time error "Unreachable Code".

I understand why I get an error message after terminating it, but my question is even if I comment on it but is bad()unavailable, since I am an throwingexception - this is catch, then why doesn’t it give an error for it?

class Varr 
{
  public static void main(String[] args) throws Exception
  { 
    System.out.println("Main");
    try {
      good();
    } catch (Exception e) {
      System.out.println("Main catch");
      //**Statement 1**    
      throw new RuntimeException("RE");
    } finally {
      System.out.println("Main Finally");
      //  **Statement 2**    
      throw new RuntimeException("RE2");
    }
    bad();
  }
}
+4
source share
1 answer

but my question, even if I comment that it is still bad () unattainable, as I throw an exception, caught then why this is not giving an error for this?

catch.
, good() , catch, bad():

public static void main(String[] args) throws Exception
{   
    System.out.println("Main");
    try {
        good(); // doesn't throw an exception
    } catch (Exception e) { 
        System.out.println("Main catch");
        throw new RuntimeException("RE");
    }
    bad(); // execution goes from good() to here
}
+3

Source: https://habr.com/ru/post/1685400/


All Articles