Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the five kinds of exception

Shulou Source: shulou.com Published: 2022-06-02 03:29:29 09月20日 Update

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.

Tags: Pointers objects results numbers content reasons types subscripts characters properties data formats compilation elegance things examples parameters strings common developers Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Docker Shulou Technology Linux MariaDB