急求啊:用java编一个自定义异常类处理字符串转换为实数时数据格式出错

来源:百度知道 编辑:UC知道 时间:2024/06/06 20:06:42
各位好心人士请帮忙回答一下哈,在此谢过了

class Myexception extends Exception{
protected Throwable throwable;
//构造方法
public Myexception()
{
super("转换错误");
}
}

public class test_1{
public void test(String str) throws Myexception {
Pattern pattern = Pattern.compile("[0-9]*");//使用正则表达式判断是不是数字
Matcher isNum = pattern.matcher(str);
if( !isNum.matches() )
{
throw new Myexception();
}

}
public static void main(String args[]){
try {
new test_1().test();
} catch (Myexception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

//异常类
class Exception{
boolean b=true;
public boolean test(String o){
try{
b=IntegerParseInt(o);
}catch(NumberFormatException e){
b=false;
}
return b;
}
}
//测试类
class ExceptionTest{
public static void main(String[] args){<