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 common exceptions in java

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

This article mainly explains "what is the common exception of java". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the common anomalies of java".

Abnormal

In a program, errors may occur in a variety of situations that the programmer did not expect, or in an environment beyond the programmer's control. In order to deal with the running errors in the program timely and effectively, Java specially introduces exception classes.

When writing code, handling exceptions generally follows the following three principles:

1. Use the try catch statement to catch an exception in the current method declaration.

two。 When a method is overridden, the method that overrides it must throw out the same exception or subclass of the exception.

3. If the parent class throws more than one exception, the override method must throw a subset of those exceptions, not new ones.

The Throwable class is the superclass of all exceptions and errors, and there are two subclasses, Error and Exception, that represent errors and exceptions, respectively.

The Exception class is used to find possible exceptions and to create custom exceptions, which are generally used by programmers to find code errors. In the exception information, we can find a lot of useful information to guide us to solve the problem. Let's take a look at one of the simplest runtime exceptions in new!

The following picture shows the error message.

It is not difficult to find that this can intuitively see the exception information, because if an error is reported, our exception is likely to be eaten by catch, but we have throw a run-time exception (RuntimeException), which can be used to remind developers and print out the exception information to facilitate error finding.

The emergence of Error is usually an exception that you do not want to be caught, because the exception of Error type shows errors related to the running system itself, such as stack memory overflow. Generally, this kind of problem will be a headache. For us developers, if we encounter Error in the production environment, it is generally catastrophic.

Our article focuses on a brief introduction to exceptions and common Exception.

1.Exception

Without much introduction, the root class of all exceptions is often seen when handled with a global exception.

2.NullPointerException

Null pointer exception, the most common, but also one of the best checked exceptions. In general, the exception message will be displayed in the error in the number of lines of your code, for example, if a line of code reports a null pointer, then it must be that you have manipulated an empty object in this line. For example, if you have just new a brand new object and do not assign a value to it, you will directly get it, and you will report NullPointerException. To put it simply, you use a null to click on other properties, such as null.get,null.set, and so on.

3.SQLException

There is an exception in operating the database. In general, this exception is your sql error. At this time, you should check your sql statement. It is recommended to copy out the sql statement in your log information and execute it.

4.ClassNotFoundException

Unable to load the required classes, this exception is the most common and troublesome for beginners. If you really can't find the problem, you can try clean your Eclipse or restart your computer.

5.NumberFormatException

A digital conversion exception, which is relatively simple, is converted to an exception that does not conform to the target digital reception format. For example, if you convert a string "1. 5" to Integer, this exception will be reported.

6.IOException

IO exception is also very common. Generally, you need to throw this exception when you need to upload files and other places where you need to operate IO.

7.ArraylndexOutOfBoundException

(index) Angle index is out of bounds, for array index, some are called angle index, some are called subscript, anyway, we just need to know that this operation array is not as long as you expected, for example, its size is 1, you go to get (2), then this exception will occur, because it does not have this exception at all.

8.IllegalArgumentException

Illegal parameter exception, which is reported when the method receives a parameter that does not match the parameter list.

There are also some exceptions that are less common or less manageable, and we also mention RuntimeException (runtime exception), FileNotFoundException (file exception not found), and InterruptedException (thread interrupt exception).

Thank you for your reading, the above is the content of "what is the common exception of java". After the study of this article, I believe you have a deeper understanding of what the common exception of java is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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

Internet Technology

Wechat

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

12
Report