About Java Exception

The java programing language provides three kinds of throwables: checked exception, run-time exceptions and errors.

Checked exceptions generally indicate recoverable conditions.

There are two kinds of unchecked throwables: run-time exceptions and errors, they are identical in their behavior:

Both are throwables that needn't, and generally shouldn't , be caught.

If a program throws an unchecked exception or an error,

it is generally the case that recovery is impossible and continued execution would do more harm than good.

If a program does not catch such a throwable, it will cause the current thread to halt with an appropriate error message.

Use run-time exceptions to indicate programming errors.

All of the unchecked throwables you implement should subclass RuntimeException(directly or indirectly).

To summarize, use checked exceptions for recoverable conditions and run-time exceptions for programming errors.

If you believe a condition is likely to allow for recovery, use a checked excepion;

If not, use a run-time exception.

If it is not clear whether recovery is possible, you are probably better off using an unchecked exception.



你可能感兴趣的:(java,thread,exception,behavior)