Java exception handling and processing framework-notes

Source: Internet
Author: User

1. Java exceptions include checked exceptions and unchecked exceptions.

Checked exceptionCodeTry ...... Catch display capture)

All exceptions that inherit java. Lang. Exception. It can be restored during execution. This type of exception is notProgramSuch as invalid user input and file does not exist. These are external reasons, none of which can be controlled within the program.

Unchecked exception (also called error, no need to show capture)

All exceptions that inherit java. Lang. runtimeexception. Is an error that cannot be processed.

2. Where should exceptions be recorded?

The location where the exception was first generated.

If the exception can be handled, no record will be made after the exception is processed. If an exception cannot be handled, You can encapsulate it as another exception and throw it up without record the recorded exception.

3. Recording abnormal behaviors that do not belong to the exception type should be done by a dedicated log system.

4. An exception handling framework is provided for the system to determine whether to record exceptions and how to record exceptions, rather than being done by common programmers.

5. For an application, all exceptions appear to the user as internal exceptions of the application system. Therefore, an application system exception framework should be designed to handle all exceptions during system operation.

You can design a general class for an application system, such as appexception. This exception and its subclass occur when the application system is running. Therefore, the appexception family should inherit from runtimeexception, in this way, all other exceptions in the system are transferred to appexception. When an exception occurs, the front-end will receive the appexception and perform unified processing.

6. In the general exception handling framework, support for configuration information and unified Exception Handling and exception log management are required, it also allows you to extend custom exception handling or logging methods in the form of plug-ins.

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.