{
String info;
public void UserException(String info) { }
public void callException() throw UserException { }
public static void main(String args) { try {
UserException ue = new UserException (); ue. callException();
throw UserException(“callException”); info = info;
}(UserException e) {
System.out.println(“产生异常:”+e.info);
}final {
System.out.println(“释放资源”);
}
}
}
1、class UserException implements Exception
改成 class UserException extends Exception
2、public void UserException(String info)
改成 public UserException(String info)
3、info = info;
改成 this.info = info;
4、public void callException() throw UserException
改成 public void callException() throws UserException
5、throw UserException(“callException”);
改成throw new UserException(“callException”); 6、public static void main(String args)
改成 public static void main(String []args) 或 public static void main(String args[])
7、UserException ue = new UserException ();
改成 UserException ue = new UserException (“”);
8、}(UserException e)
改成 }catch (UserException e)
9、}final 改成 }finally
相关推荐: