1.classMyExceptionextendsException{}publicclassSample{publicvoidfoo(){try{System.out.print(1);bar();System.out.print(2);}catch(MyExceptione){System.out.print(3);}finally{...
1.class MyException extends Exception{}
public class Sample{
public void foo(){
try{
System.out.print(1);
bar();
System.out.print(2);
}catch(MyException e){
System.out.print(3);
}finally{
System.out.print(4);
}
}
public void bar() throws MyException{
throw new MyException();
}
public static void main(String args[]){
Sample s=new Sample();
s.foo();
}
}
2.
class MyException extends Exception{}
public class Sample{
public void foo(){
try{
System.out.print(“a”);
bar();
System.out.print(“b”);
}catch(MyException e){
System.out.print(“c”);
}finally{
System.out.print(“d”);
}
}
public void bar() throws MyException{
throw new MyException();
}
public static void main(String args[]){
Sample s=new Sample();
s.foo();
}
}
展开