In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
The knowledge of this article "how to deal with exception types in Java" is not quite understood by most people, so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to deal with exception types in Java" article.
I. description of anomalies
The unexpected event that occurs when the program is running, which prevents the program from executing as expected by the programmer, is an exception. When an exception occurs, the program is left to fend for itself and immediately exits and terminates. In Java, an error that occurs when Java is compiled or run or run.
Java provides an even better solution: exception handling.
The exception handling mechanism enables the program to deal with the exception pertinently according to the pre-set exception handling logic of the code when the exception occurs, so that the program can return to normal and continue to execute as much as possible, and keep the code clear.
The exception in Java can be thrown when the statement in the function is executed, or it can be thrown manually by the programmer through the throw statement. Whenever an exception is generated in the Java program, an exception object of the corresponding type will be used to encapsulate the exception, and JRE will try to find an exception handler to handle the exception.
An exception refers to an abnormal situation that occurs during the run time.
In java, abnormal conditions are described and encapsulated in the form of classes.
A class that describes an abnormal situation becomes an exception class.
Separate the normal code from the problem handling code to improve readability.
In fact, exception is that java encapsulates the problem into an object through the idea of object-oriented, and describes it with exception class.
2. Abnormal system
Two main categories:
Hrowable: an exception that can be thrown, whether error or exception, should be thrown when a problem occurs, so that the caller knows and handles it.
The characteristic of this system is that Throwable and all its subclasses are disposable.
What exactly does disposability mean? How to reflect the disposability?
It is reflected by two keywords.
Throws throw all classes and objects that can be manipulated by these two keywords are disposable.
Subclass 1 is generally unmanageable. -Error
Features: it is a serious problem thrown by jvm, this kind of problem is generally not targeted to deal with, directly modify the program.
Subcategory 2) can be handled. -Exception, the question is thrown to the caller, who uses it to whom.
Features: the suffix names of subclasses all use the parent class name as the suffix name, which is very readable!
Example: for example, customize a negative corner exception and encapsulate it into an object using object-oriented thinking.
Note: if you call a class an exception class, you must inherit the exception class. Because only the subclasses of the exception system can be thrown.
The class FuShuIndex extends Exception {/ / constructor is the same as the class name FuShuIndex () {} / / defines a constructor with parameters FuShuIndex (String msg) {/ / calls the exception function with parameters super (msg) in Exception }} main function throws FuShuIndex: {int [] arr = new int [3]; method (arr,-7);} public static int method (int [] arr,int index) throws arrIndexexception {if (index
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.