Common types of exceptions in Java

Source: Internet
Author: User

Exceptions are broadly divided into compiler exceptions and run exceptions, and if you compile exceptions with software development (such as Eclipse), you get reminders when you write code, and running exceptions need to be prompted at run time.

Here are a few common types of exceptions that make it easy to check for errors when they occur:

(1) Exception the root class of various anomalies

You can define an exception type as exception if you do not know where the exception will occur and you can be certain that an exception will occur in this place.

(2) ArithmeticException arithmetic arithmetic error exception

This exception is often encountered in arithmetic operations, and the common case is the exception thrown when the divisor is 0.

(3) Arrayindexofoutboundsexception array subscript out of bounds

When programming, remember that the subscript for the Java array starts at 0, the array subscript maximum is reduced by 1, such as arr[10], the last array element is arr[9], and arrayindexofoutboundsexception exception occurs if written arr[10].

(4) nullpointexception null pointer exception

This exception is the exception that is thrown for calling an uninitialized or undefined object.

(5) ClassNotFoundException cannot load the required classes

After the Java file is compiled, it may be necessary to move the. class file to a different folder, at which point the. class file should be noted to modify its path, or the classnotfoundexception exception will be thrown.

(6) Inputmismatchexception input data type does not match the desired type of exception

For example, if you need an int type, but you get a string type from the input box, the inputmismatchexception exception will be thrown.

(7) IllegalArgumentException method accepts illegal parameters

This is an incorrect parameter type in the incoming method, such as method plus (int a,int b), which appears when written as A.plus (1,a).

IllegalArgumentException exception.

(8) NumberFormatException string converted to numeric exception

The exception that occurs when the data type is cast, the string "123" is converted to the number 123 without an exception, but the string "[email protected]" is converted to type int to throw a classcastexception exception.

Common types of exceptions in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.