throw抛出异常

package four;

import java.io.*;

public class TestThrowException extends Exception

{

public static void square(double n) throw TestThrowException 

{

if(n<0.0)

throw new TestThrowException();

else

        Math.sqrt(n);

}

public static void main(String[] args)throws IOException

{

double number = 0 ;

TestThrowException tt = new TestThrowException() ;

try

{   

System.out.println("input double number");

BufferedReader br= new BufferedReader(new InputStreamReader(System.in));

String s = br.readLine() ;

number = Double.parseDouble(s);

tt.square(number);

}

catch( TestThrowException e1)

{

System.out.println(e1.toString()+"输入数据有误");

}

}

}

这段代码报错是TestThrowException不是throwable的

求修改

1525155750
浏览 1319回答 1
1回答

Caballarii

public static void square(double n) throw TestThrowException 应该是throws
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java