The largest class in the exception is Throwable, which is divided into two subclasses: Exception,error
Exception: Is an exception that the program can handle
Error: Indicates JVM errors, general program cannot handle
The difference between exception and runtimeexception:
1. If the type of exception is thrown, it must be processed using Try...catch.
2. If the type of runtimeexception is thrown, it is not necessary to use try...catch for processing, and once an exception occurs, it will be handled by the JVM, but in order to ensure the health of the program, it is recommended to use a try if there is a possibility of an exception ... catch to handle.
Throws the difference between the keyword and the throw keyword:
1. When defining a method, you can use the throws keyword declaration, which uses the throws declaration method to indicate that this method does not handle the exception, and that it is handled at the call of the method.
2. You can use the Throw keyword to artificially throw an exception, throwing an instantiated object that throws the exception class directly
Custom exception Classes
Custom exception classes can be completed only by inheriting exception, and you can customize the exception class when you need to define the exception information you want.
Example:
Class MyException extends exception{//Custom exception class, inheriting Exception class
Public myexception (String message) {//constructor method receives exception information
Super (message); Calling a construction method in a parent class
}
}
public class Defaultexception {
public static void Main (string[] args) {
try {
throw new MyException ("Custom Exception");
} catch (Exception e) {
E.printstacktrace ();
}
}
}
A little understanding of the anomaly