In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the relevant knowledge of "what is the common exception handling in JAVA projects". The editor shows you the operation process through actual cases, and the operation method is simple, fast and practical. I hope this article "what is the common exception handling in JAVA projects" can help you solve the problem.
1. Null pointer exception (java.lang.nullpointerexception)
This usually occurs when string variables are not initialized, arrays are not initialized, class objects are not initialized, and so on. There is also a situation in which you do not judge whether the object is null or not. I made this mistake on the previous web exercise, so in order to avoid this situation, in addition to checking whether it is initialized, add an if statement to determine whether it is null if necessary.
two。 The specified class does not exist (java.lang.ClassNotFoundException)
One of the reasons for this error is that there is a lack of package, so just download and import the corresponding package; when we have already imported the package and reported this error, we need to open our own editor to adjust the settings; when using tomcat, first check whether jar is imported into lib.
3. Convert string to numeric exception (java.lang.NumberFormatException)
This error is that an exception occurs when converting a non-numeric character to a number in a string; in addition, this error can also occur if the string is converted to a number beyond the range of the type (such as string to int and string to double). The solution to this problem is to check the string before conversion.
4. Array subscript out of bounds exception (java.lang.IndexOutOfBoundsException)
As the name implies, the array elements you want to take are not defined in the array, such as defining an array an of length 5, which is bound to make an error when you want to take a [6] element. To solve this kind of problem is to pay attention to the length of the array. Sometimes we use the dynamic array construction method to reduce the waste of space. When operating on the array, it is recommended to use length to get the length of the array, so as to avoid errors.
5. Mathematical operation exception (java.lang.ArithmeticException)
The error is reported when the divisor is 0, and the solution: avoid divisor 0. This error is interpreted as "abnormal operation conditions". In addition to the case where the divisor is 0, there may be other abnormal situations, which will be analyzed in detail.
6. No access (java.lang.IllegalAccessException)
Permission problem, when the program accesses a method, just pay attention to the access right (public/private). This kind of error is easy to occur when using package.
7. Method has the wrong parameters (java.lang.IllegalArgumentException)
When calling a method with parameters, note that the parameters passed are correct.
8. Data type conversion exception (java.lang.ClassCastException)
This error is easy to occur when the forced type conversion is carried out, and the type is distinguished before the conversion to avoid the error.
9. No exception found in the file (java.lang.FileNotFoundException)
This error is reported when a program tries to open a non-existent file for read and write operations, usually issued by the constructor declaration of FileInputStream,FileOutputStream,RandomAccessFile, even if the file exists but cannot be accessed for some reason.
10. Array storage exception (java.lang.ArrayStoreException)
If you put a variable of type string in an int array, you will get an error. The solution is to find out the type when you store the object, or to cast the type before saving it.
11. Method has no exception (java.lang.NoSuchMethodException)
The method to be called by the program does not exist. Solution: do not call or construct its methods.
twelve。 File closed exception (java.lang.EOFException)
This exception is thrown when the program encounters the end of a file or stream during program input, which is used to check whether the end of the file or stream has been reached.
13. Instantiate exception (java.lang.InstantiationException)
Class cannot be instantiated through the constructor when creating a new object. Solution: construction method.
14. Aborted exception (java.lang.InterruptedException)
Abort an error made by another thread through the interrupt method of the Thread of another thread. The solution is: first, throw directly without processing; second, catch the exception, call the interrupt method again, and reset the interrupt state to true.
15. Clone exception (java.lang.CloneNotSupportedException) is not supported
If the Cloneable interface is not implemented, the clone method is called to report the error; if the class does not support the Cloneable interface, the error will also occur when it is called. Solution: implement the Cloneable interface.
16. Input / output exception (IOException)
This exception is a branch of Exception and usually occurs on the data read and write of the file.
17. Error (java.lang.Error)
The base class of all errors, used to identify serious program running problems. The common reason is that there are a series of problems when accessing external resources, and the solution needs to focus on accessing external resources.
This is the end of the content about "what are the common exception handling in JAVA projects?" Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.