Home  >  Article  >  Java  >  Things to note about Java custom exception classes

Things to note about Java custom exception classes

WBOY
WBOYforward
2023-04-26 16:19:071105browse

1. Notes

(1) For a parent class method overridden by a subclass, the exception type thrown by it can only be the exception class of the overridden method. Subclass or itself

(2) Among them, it is necessary to distinguish: the difference between throw and throws

2. Instance

Customized exception class inheritance The existing exception class

provides a sequence number and several overloaded constructors

public class MyException extends Exception{
    
static final long serialVersionUID = -70348975766939L;
        
public MyException(){}
        
public MyException(String msg){
super(msg);
}
}

The above is the detailed content of Things to note about Java custom exception classes. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete