The operating environment of this tutorial: Windows 7 system, Java 10 version, DELL G3 computer.
1. Points of attention
(1) For a parent class method overridden by a subclass, the exception type thrown by it can only be a subclass of the exception class of the overridden method or itself.
(2) Among them, it is necessary to distinguish: the difference between throw and throws
2. Example
Custom exception classes inherit existing exception classes
Provide a serial number and provide several overloaded constructors
public class MyException extends Exception{ static final long serialVersionUID = -70348975766939L; public MyException(){} public MyException(String msg){ super(msg); } }
The above are the points to note about Java custom exception classes. I hope it will be helpful to everyone.