Exception Handling in Java

Source: Internet
Author: User

1. What is an exception?

Exceptions are things that prevent the program from running properly, and when an exception occurs, the program will terminate and the system will form some error messages, and the best thing for the exception is that they can be processed.

2. When does an exception occur?

Exceptions can occur at run time (runtime exceptions) or at compile time (Compile-time exception)

3. Cause of the exception

There are some reasons for an exception, for example, the following situation will cause an exception, open a nonexistent file, network connectivity issues,

The operation has exceeded the predefined range, the class file has not been found, and so on.

4. Differences between errors and exceptions

Error: Represents some of the issues that the app should not handle, which are not expected to be handled in the usual circumstances, such as: Memory errors,

Hardware problems, JVM issues, and so on.

Exceptions: Exceptions are included in the code, and developers can handle such problems using the correct method, such as the following exception, DivideByZero exception NullPointerException ArithmeticException ArrayIndexOutOfBoundsException

5. Benefits of Exception handling

Exception handling allows us to control the flow of the program.

6. Why Handle Exceptions

is to return friendly warning messages to the user, in most cases due to user-supplied error data that caused the exception to occur.

7. Types of exceptions

Detectable exceptions

Non-detectable exception

Except that runtime exceptions are called detectable exceptions, such as:

ClassNotFoundException
IllegalAccessException
NoSuchFieldException
EOFExceptionetc.

Runtime exceptions are called non-detectable exceptions, such as:

ArithmeticException
ArrayIndexOutOfBoundsException
NullPointerException
NegativeArraySizeExceptionetc.

Exception Handling in Java

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.