Java exception mechanism
The java.lang.Throwable types in Java inherit from the. Error type inherits from Java.lang.Error. The Exception type inherits from Java.lang.Exception.
For example:
1.IllegalAccessException exception
2.IllegalArgumentException exception
3.IllegalAccessError
Abnormal and non-checked anomalies
Both RuntimeException and error are compiled without capture, known as non-checked exceptions. (Of course both can be captured)
All other exception types need to be captured.
If a method throws a checked exception and does not capture itself, the throws must be declared at the tail of the function signature for capture.
Note: If a catch statement attempts to catch a checked exception, the checked exception or its subclass must be thrown in the try statement, or the compilation will be an error.
For example
Try { System.out.println ("Nothing Happened");
} catch(illegalaccessexception e) { System.out.println (e); }
The meeting error "Cannot throw exception error in the body of the corresponding try statement illegalaccessexception"
Method can throw an exception at any location using throw.
Java exception mechanism