自定义异常类:
public class CustomException extends Exception{
public CustomException(){}
public CustomException(String message){
super(message);
}
// public CustomException(param ..){...}
}
main():
try{
try{
Class<?> clazz = Class.forName(className);
Method method = Clazz.getDeclaredMethod(Param);
method.invoke();
}catch(InvocationTargetException ext){
try{
throw ext.getTargetException();
}catch(CustomException cusEx){
throw cusEx;
}catch(Throwable e){
// TODO
}
}
}catch(CustomException ex){
// TODO
}catch(Exception e){
// TODO
}
public class CustomException extends Exception{
public CustomException(){}
public CustomException(String message){
super(message);
}
// public CustomException(param ..){...}
}
main():
try{
try{
Class<?> clazz = Class.forName(className);
Method method = Clazz.getDeclaredMethod(Param);
method.invoke();
}catch(InvocationTargetException ext){
try{
throw ext.getTargetException();
}catch(CustomException cusEx){
throw cusEx;
}catch(Throwable e){
// TODO
}
}
}catch(CustomException ex){
// TODO
}catch(Exception e){
// TODO
}