可以不用死循环的,用递归一样可以实现下面是个简单的例子import java.util.Scanner;public class Test public static void main(String[] args) Test t = new Test(); t.input(); } public void input() Scanner s = new Scanner(System.in); System.out.println("Please input a num"); try int num = s.nextInt(); System.out.println("You input "+num); } catch(Exception e) System.out.println("Invalid input,try again"); input(); } }}boolean flag=true;while(flag)try//代码,所有代码执行完后加下那一句。flag=false;}catch(Exception e)//代码}}你要在dosql方法里向外抛异常,外面才能捕捉到, throw 出来。 像这样: dosql() try // 。。。。 }catch(exception ee) throw ee; } }