What is an exception: abnormal, different from normal, not grammatical error.
The exception is not a grammatical error, the syntax is wrong, the compilation can not pass, will not produce bytecode files, can not run at all.
Abnormal condition (after program interruption)
1, Error: errors, generally refers to the JVM-related unrecoverable errors, such as system crashes, memory overflow, etc.;
2, Exception: Indicates an exception, refers to an abnormal situation in the program, the problem can be repaired (handling exceptions) using Try-catch to catch a single exception
try{
Code
}catch (Exception type E) {} for which an exception might occur
Experiment:
public static void Main (string[] args) {
System.out.println ("Begin ...");
try {
int ret = 10/0;
SYSTEM.OUT.PRINTLN ("result =" +ret);
} catch (ArithmeticException e) {
System.out.println ("abnormal!!!");
System.out.println (e);
}
System.out.println ("End ...");
}
Console execution Results:
Begin ...
Out of the ordinary!!!
Java.lang.ArithmeticException:/By zero end
...
Process finished with exit code 0