class Exception3{ public static void main(String args[]){ //try{ /* SuperOne so = new SuperOne(); so.setVar(-5); System.out.println(so.getVar()); */ SuperTwo st = new SuperTwo(); st.setSO(-5); System.out.println(st.so.getVar()); /* }catch(oneException oe){ oe.printStackTrace(); }catch(Exception e){ e.printStackTrace(); }//catch */ }//main }//Exception3 class oneException extends RuntimeException{ public oneException(String message){ super(message); System.out.println(message); } }//oneException class SuperOne{ int var; SuperOne(){} public void setVar(int v){ if(v < 0) throw new oneException("v cannot less than 0, set as 1."); else var = v; }//setV1 public int getVar(){ return var; }//getV1() }//SuperOne class SuperTwo{ SuperOne so; SuperTwo(){ so = new SuperOne(); } public void setSO(int i) throws oneException{ try{ so.setVar(i); }catch(oneException e){ so.var = 1; }//catch }//setSO() }//SuperTwo