-2

I dont think I can better specify the question...

suspicious
  • 43
  • 1
  • 2
  • 9
  • 3
    Maybe you can find the answer here: http://stackoverflow.com/questions/2190161/difference-between-java-lang-runtimeexception-and-java-lang-exception – Keppil Dec 30 '15 at 15:37

2 Answers2

0

There are a lot of such exceptions are called "runtime exceptions". RuntimeException for an example.

v.ladynev
  • 19,275
  • 8
  • 46
  • 67
  • But why are only RuntimeExceptions thrown by default? – suspicious Dec 30 '15 at 15:41
  • @suspicious read [`RuntimeException`](https://docs.oracle.com/javase/8/docs/api/java/lang/RuntimeException.html): *RuntimeException and its subclasses are unchecked exceptions. Unchecked exceptions do not need to be declared in a method or constructor's throws clause if they can be thrown by the execution of the method or constructor and propagate outside the method or constructor boundary*. – Luiggi Mendoza Dec 30 '15 at 15:42
  • @suspicious An inventor of the Java language made such decision. – v.ladynev Dec 30 '15 at 15:44
  • But what does default exception throwing has to do with the fact that they are unchecked? I think you are confusing the question. And don't mark it a duplicate luiggi. ITS NOT! – suspicious Dec 30 '15 at 15:51
  • @suspicious What do you mean by "default exception throwing"? – v.ladynev Dec 30 '15 at 15:54
  • @v.ladynev let me demonstrate with an example. I have a method called division() that performs a division by zero. I call this method from the main method. In the division() method i have not included a "try{ } catch() { }" block, nor have I included the "throws ArithmeticException" when declaring my method. But when I call the method from main it goes like this: try { division(); } catch(ArithmeticException e) { System.out.println("Division by zero detected"); } And even though I have not used "throws ArithmeticException" when declaring my method, the exception handling in "main" worked – suspicious Dec 30 '15 at 16:03
  • @suspicious In the real systems you will not do such kind of things `try { division(); } catch(ArithmeticException e) { System.out.println("Division by zero detected"); } ` you will just allow an `ArithmeticException` goes to the top level :) Exception "worked" because of the type of it "runtime exception". – v.ladynev Dec 30 '15 at 16:06
  • @v.ladynev It doesn't matter what you do in real life for christ's sake. Did you ven understand me? – suspicious Dec 30 '15 at 16:08
  • @suspicious I am not sure. Ok. You don't need to declare `ArithmeticException` in the `throws` clause because of it descendant of `RuntimeException`. – v.ladynev Dec 30 '15 at 16:11
  • @v.ladynev so the main function, in my example (with is the caller) will deal with the exception anyway, even if the division() method doesn't declare "throws Arithmetic Exception" ? – suspicious Dec 30 '15 at 16:14
  • @suspicious Yeah. You got it. Checked exceptions are bullshit in my opinion. You should always be ready to have an exception rising in any part of the code. – v.ladynev Dec 30 '15 at 16:18
  • @v.ladynev you are awesome sir! – suspicious Dec 30 '15 at 16:25
  • @suspicious you are welcome – v.ladynev Dec 30 '15 at 16:28
0

Yes. Anything inherited from RuntimeException or Error.

The first means some unhandled issues in your code, the Error means serious problem with JVM like out of memory, stack overflow etc.

Zbynek Vyskovsky - kvr000
  • 18,186
  • 3
  • 35
  • 43