为了账号安全,请及时绑定邮箱和手机立即绑定

throw抛出异常

throw抛出异常

1525155750 2016-03-31 19:50:27
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的求修改
查看完整描述

1 回答

已采纳
?
Caballarii

TA贡献1123条经验 获得超629个赞

public static void square(double n) throw TestThrowException 

应该是throws

查看完整回答
反对 回复 2016-04-01
  • 1 回答
  • 0 关注
  • 1276 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信