Error classifications for Java

Source: Internet
Author: User

Error classifications for Java
Errors in Java fall into two main categories: Error and exception errors.


Error is a bug that cannot be handled by a program, which means that it is not possible to modify the program itself because of the more serious problems in running the application. Examples include system internal errors (virtual machine errors) generated by the Java runtime, and errors caused by resource exhaustion.

Exception is an exception class that represents an error that the program itself can handle. It is mainly divided into non-running exceptions and running exceptions.
1. Non-runtime exception (compilation exception)
IOException Exception
Represents the exception class that is generated by a failed or interrupted I/O operation.
SqlException Exception
Represents an Access database error or database information error.

2. Run-time Exceptions(runtimeexception)
Common run-time exceptions:
ClassCastException (class conversion exception) Public classdemo{ Public Static voidMainString[] args) {Object x =NewInteger (0); System.out.println((String) x); }}

Stringindexoutofboundsexception (String corner bounds exception)

Public classDemo { Public Static voidMainString[] args) {Strings ="ABCDEFG"; System.out.Print(S.charat (9)); }}

ArrayIndexOutOfBoundsException (array corner bounds exception)

Public class Demo{Public static void main(string[] args){int[] arr =New int[4]; System. out. println ("arr[0]="+arr[4]); }}

NullPointerException (null pointer exception)

Public class HelloWorld{Public static void main(string[] args){int[] arr =New int[4]; arr[0] =5; System. out. println ("arr[0]="+arr[0]);
arr =NULL; System. out. println ("arr[0]="+arr[0]);//Error}}

Arraystoreexception (data store exception, type inconsistency when manipulating arrays)

Public classtest{ Public Static voidMainString[] args) {Object x[] =New String[3]; x[0] =NewInteger (0); System.out.println(x[0]); }}

ArithmeticException (Arithmetic exception)

Public class Finderror{Public static void main(string[] args){intx =4, y =0;intresult = x/y; System. out. print (result); }}

Error classifications for 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.