Java Exception Summary:
An exception is when the program is running in an unhealthy state
1. The origin of the anomaly:
A description of the problem in the real thing in the form of a Java class, and it is sealed into an object
In fact, Java is the object of the description after the abnormal situation
2. There are two types of problems: one is serious, the other is a non-serious problem.
For serious, Java is described by the error class
For error It is generally not written with specific code to handle it
For non-critical, Java is described by the exception class
For exception can be handled with a targeted approach
3. Common exceptions are: array angle label out of bounds exception, NULL pointer exception ...
4. Both error and exception have some common content.
For example: abnormal information, cause of the causes and so on.
Throwable//Parent class
|--error
|--excption//Two subcategories (there are many problems defined (exceptions appear))
Example 1:
1 classDemo2 {3 Public intDivintXinty)4 {5 returnx/y;6 }7 }8 9 Ten classExceptiondemo One { A Public Static voidMain (String args[]) - { -Demo d=NewDemo (); the intX=d.div (4,0); 0 as Divisor -System.out.println ("x=" +x); -System.out.println ("Over"); - } +}
Operation Result:
Exception in thread "main" java.lang.ArithmeticException:/By zero
At Demo.div (exceptiondemo.java:5)
At Exceptiondemo.main (exceptiondemo.java:15)
From the above results can be analyzed, in the 5th and 15th lines have an exception, this is because of the division mechanism, the divisor cannot be 0, this time the run throws an exception.
Example 2:
1 classDemo2 {3 Public intDivintXinty)4 {5 returnx/y;6 }7 }8 9 Ten classExceptiondemo One { A Public Static voidMain (String args[]) - { - /*Demo D=new demo (); the int X=d.div (4,0); - System.out.println ("x=" +x); - System.out.println ("over"); - */ + byte[] arr=New byte[1024*1024*1000]; - } +}
Operation Result:
Exception in thread "main" Java.lang.OutOfMemoryError:Java heap space
At Exceptiondemo.main (exceptiondemo.java:19)
Java.lang.OutOfMemoryError: represents a memory overflow exception
Full description of the exception mechanism in Java