0

i try

package ro.ex;

/**
 * Created by roroco on 11/4/14.
 */

class Ex {

    public void m() {
        throw new Exception();
    }

    public void m2() {
        throw new RuntimeException();
    }
}

in throw new Exception();, intellij idea raise "Unhandled exception: java.lang.Exception", but in throw new RuntimeException(); it's not, my question is: what cause this diff?

  • 1
    http://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html – user2336315 Nov 07 '14 at 08:15
  • 2
    RuntimeException is a un-checked exception i.e. the compiler does not check for its handling at compile time. On the other hand, a checked exception is checked by the compiler and must be either handled explicitly or declared on the method. Now why these exceptions exist in Java is a matter related to design choice of the language itself. – Ironluca Nov 07 '14 at 08:18
  • http://stackoverflow.com/a/2190175/14955 – Thilo Nov 07 '14 at 08:18

1 Answers1

3

See this link about checked and unchecked exceptions

enter image description here

Scary Wombat
  • 44,617
  • 6
  • 35
  • 64