Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the five kinds of exception

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about what the five kinds of exception are, which may not be well understood by many people. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something from this article.

Null pointer (Java.lang.NullPointerException)

1. What is it (what): a null pointer is the most common mistake made by Java developers. It annoys you when you see it, usually because the property of the object has no value.

2. The first object with a null pointer is the object (no problem), not the basic data type, because the basic data type has no comparison assignment, and the compiler will not compile through.

A) give an example

Result

3. The null value is not the reason for the null pointer.

Result

4. The reason for the null pointer is to go to the null value (attribute).

Result

5. Solution: when creating an object, determine whether the object is a null value, not a null value. If it is a null value, print and press to return to the corresponding page instead of a null pointer. Make the program elegant and responsible for the user experience.

6. In addition, using the equal method to judge that we should pay attention to putting the parameters of the value of the object after can avoid null pointer exception.

Result

Put it in the back

As a result, the output false with no null pointer

Arithmetic operation exception

The divisor is 0

Array subscript exception

Cross the line

String subscript exception

Cross the line

Numeric format exception

Only numeric characters can be converted to numeric integers

Int I = Integer.parseInt ("ab3")

Abnormal number format will be reported.

Type replacement exception Object obj=new Object (); String s = (String) obj;java.lang.ClassCastException: java.lang.Object cannot be cast to java.lang.String after reading the above, do you have any further understanding of what the five exception are? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report