import java.io.*;public class Test5 {
 public void doException() throws IOException {
System.out.println("arithmeticExcption");
} public static void main(String[] args) {
Test5 test = new Test5();
 
test.doException();
}
}

解决方案 »

  1.   

    public void doException() throws IOException {
    改成:
    public void doException() {
      

  2.   

    捕获一下异常不就行了么
    代码
    import java.io.*;public class Test5 {
    public void doException() throws IOException {
    System.out.println("arithmeticExcption");
    }public static void main(String[] args) {
    try{
    Test5 test = new Test5();
      
    test.doException();
    }catch(Exception e){
    }
    }
    }
      

  3.   

    有提示信息的嘛,因为你定义的方法是抛出(throws IOException ),所以方法的调用寻妖抛出
    package test1;import java.io.*;public class Test5 {
    public void doException() throws IOException {
    System.out.println("arithmeticExcption");
    }public static void main(String[] args) {
    Test5 test = new Test5();
      
    try {
    test.doException();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }
      

  4.   

    3L说的对。Java中如果定义的方法会抛出异常,那调用的时候就一定要捕捉该异常,当然如果你忘了会抛出什么异常,那直接用Exception就行了。
      

  5.   

    有异常你没捕获
    doException本身throw了异常,在main中必须try-catch一下,或者把main声明一下throw 一个exception
      

  6.   

    调用的函数doException()里申明抛出异常,这里的main()函数里也应该抛出这个异常
      

  7.   

    有异常抛出机制的函数A,其他函数比如B调用A的时候要么try块进行处理,要么B也throws继续抛,然后让别的函数或者程序段调用B的时候来做处理。
      

  8.   

    因为你的方法把异常抛出给函数的调用者了,所以你必须要在调用函数的地方捕获这个异常:import java.io.*;
    /**
     * 
     * @author supercodingman
     * @version 1.0
     */
    public class Test5 {
    public void doException() throws IOException {
    System.out.println("arithmeticExcption");
    }
    public static void main(String[] args) {
    Test5 test = new Test5();
    try {
    test.doException();//所抛出的异常会返回给调用者处理
    } catch (IOException e) {
    e.printStackTrace();
    }
    }
    }
    你也可以换成把throws的方式换成try/catch块:
    package csdn.javase.excep.ex1;
    import java.io.*;
    /**
     * 
     * @author supercodingman
     * @version 2.0
     */
    public class Test5 {
    public void doException(){
    try{
    System.out.println("arithmeticExcption");
    throw new IOException();
    }catch(IOException ioe){
    ioe.printStackTrace();
    }
    }
    public static void main(String[] args) {
    Test5 test = new Test5();  
        test.doException();//这样就不需在调用处捕获异常了
    }
    }
      

  9.   

    呵呵,我不觉得发这种贴有什么好丢人的。学习是一个过程,说不准楼主很快就比你更精通java。
      

  10.   

    我也经常犯这样的错误  throw了异常  没有抛出
      

  11.   

    两种方法。一种是主函数继续往外抛异常。一种是上面讲的一样捕捉异常。但是应该捕捉!
    import java.io.*;public class Test5 {
    public void doException() throws IOException {
    System.out.println("arithmeticException");
    } public static void main(String args[]) throws Exception {
    Test5 test = new Test5();
    test.doException();
    }
    }
      

  12.   

    import java.io.*;public class Test5 {
    public void doException() throws ArithmeticException {  System.out.println("arithmeticExcption");
    } public static void main(String[] args){
    Test5 test = new Test5();
     
    test.doException();//是否可以通过编译
    }
    }
    谢谢,这两种都是可行的,但用ArithmeticException不用IOException也可以通过编译,为什么呢