Thread: Threads
An exception is a processing mechanism that provides a way to check for errors in a program and to return a better interface.
An exception is not a compile-time error, but a run-time error that can only be captured when a run-time error occurs.
You can catch the error and continue executing the remaining code. The program continues to execute
The process by which the Java program handles exceptions:
After a statement throws an exception, it throws an exception to the current function to see if there is a try catch statement to catch and handle the exception, and if not, returns the previous function to continue throwing an exception to see if there is a try catch statement, and if there is no JVM virtual machine to throw to Java's JRE, Then the virtual machine gives a rough deal--the program stops running.
Of course, if there is no exception, the program runs normally
try{
......
}
Catch the error message, E is used to receive the exception object ArrayIndexOutOfBoundsException stack Overflow
catch (ArithmeticException e) {
E.printstacktrace ();//Can be understood as the specific information that outputs the exception.
......
}
Try catch has no effect on code optimization
Exceptions only output one from the most recent try catch, and then continue to run normal code.
Some common exceptions are:
All exceptions are subclasses of exception.
Try catch usage for exception handling--java