Y
Y
Ytsu Ytsuevich2014-12-17 17:51:17
Java
Ytsu Ytsuevich, 2014-12-17 17:51:17

Java. Why doesn't IllegalArgumentException require throws?

Why doesn't IllegalArgumentException require throws?

void some() {
    throw new IllegalArgumentException();    // тут всё нормально, throws не нужен
  }
void some2() {
    throw new Exception();                   // тут ошибка, необходимо try/catch либо throws
  }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Power, 2014-12-17
@Power

Read about what checked exceptions and unchecked exceptions are.

A
axmexa, 2014-12-17
@axmexa

Because IllegalArgumentException extends RuntimeException.
Ah, RuntimeException is UNCHECKED. That's why you don't need try/catch.
In general, you should read about checked / unchecked.
At least here .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question