notes

Error is run out of the JVM

Exception is divided into runtime exception and check exception

1) Checked exceptions

We are more familiar with Checked exceptions include Java. Lang, a ClassNotFoundException

Java. Lang. NoSuchMetodException, we can throw or a try… catch

(2) RuntimeException

For example, if the divisor is 0 and the array subscript is out of bounds, you can capture it if necessary

java.io.IOExceptionThe original

Link: www.nowcoder.com/questionTer… Source: Niuke.com

Throwable is the root of all exceptions, java.lang.Throwable Error is an Error, java.lang.Error Exception is an Exception, java.lang.Exception

Second, the Exception

There are generally Checked exceptions and Runtime exceptions. All runtimeExceptions and their subclasses are called Runtime exceptions. Exceptions that do not fall into this category are called CheckedException.

1) Checked exceptions

Only the Java language provides Checked exceptions, and Java assumes that Checked exceptions are exceptions that can be handled, so Java programs must display handled Checked exceptions. If the program does not handle Checked exceptions, the program will fail to compile at compile time. This exemplifies Java’s design philosophy: code that has not perfected error handling has no chance at all of being executed. There are two ways to handle Checked exceptions

1 The current method knows how to handle this exception. Try… Catch block to handle the exception.

2 The current method does not know how to handle the exception.

Some of the Checked exceptions that we’re familiar with are

Java.lang.ClassNotFoundException

Java.lang.NoSuchMetodException

java.io.IOException

(2) RuntimeException

Runtime such as the divisor is 0 and the array subscript is out of bounds, it occurs frequently, processing trouble, if display declaration or capture will have a great impact on the readability and efficiency of the program. So the system detects them automatically and passes them to the default exception handler. Of course you can also display them if you have processing requirements.

The more familiar subclasses of the RumtimeException class are

Java.lang.ArithmeticException

Java.lang.ArrayStoreExcetpion

Java.lang.ClassCastException

Java.lang.IndexOutOfBoundsException

Java.lang.NullPointerException

Third, the Error

When an uncontrollable error occurs in a program, the usual practice is to notify the user and abort the program. Unlike exceptions, objects of Error and its subclasses should not be thrown.

Error, a subclass of throwable, represents compile time and system errors and is used to indicate serious problems that a reasonable application should not attempt to catch.

Error is generated and thrown by the Java VIRTUAL machine, including dynamic link failure and VM Error. The program does nothing about it.