自定义异常
Topic sourcepublic class Main {
public static void main(String[] args) {
try {
System.out.println(Tro(-5)); } catch (Exception e) {
System.out.println("catched"); throw new AbcException(e); }
}
public static int Tro(int a){
if(a<0){
throw new AbcException("参数为负"); }
return a; }
}
class BaseException extends RuntimeException {
public BaseException(){
}
public BaseException(String Message){
super(Message); }
public BaseException(String Message,Throwable cause){
super(Message,cause); }
public BaseException(Throwable cause){
super(cause); }
}
class AbcException extends BaseException{
public AbcException(){
}
public AbcException(String Message){
super(Message); }
public AbcException(String Message,Throwable cause){
super(Message,cause); }
public AbcException(Throwable cause){
super(cause); }
}
- 1
呀