Try catch usage for exception handling--java

Source: Internet
Author: User
Tags try catch

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.