packagecom.hcong.exceptions;/**
* @Classname FullConstructors
* @Date 2023/4/15 13:42
* @Created by HCong
*/classMyExceptionextendsException{MyException(){}MyException(String msg){super(msg);}}publicclassFullConstructors{publicstaticvoidf()throwsMyException{System.out.println("Throwing MyException from f()");thrownewMyException();}publicstaticvoidg()throwsMyException{System.out.println("Throwing MyException from g()");thrownewMyException("Originated in g()");}publicstaticvoidmain(String[] args){try{f();}catch(MyException e){
e.printStackTrace(System.out);}try{g();}catch(MyException e){
e.printStackTrace(System.out);}}}
ThrowingMyException from f()com.hcong.exceptions.MyException
at com.hcong.exceptions.FullConstructors.f(FullConstructors.java:20)
at com.hcong.exceptions.FullConstructors.main(FullConstructors.java:30)ThrowingMyException from g()com.hcong.exceptions.MyException:Originated in g()
at com.hcong.exceptions.FullConstructors.g(FullConstructors.java:25)
at com.hcong.exceptions.FullConstructors.main(FullConstructors.java:36)Process finished withexit code 0