本帖最后由 武维京 于 2014-5-28 22:18 编辑
- package Exception;
- class FuShuException extends Exception{
- FuShuException(String msg){
- super(msg);
- }
- }
- class Demo4{
- int div (int a,int b) throws FuShuException{
- if(b<0){
- throw new FuShuException("除数为负数");
-
- }
- return a/b;
- }
- }
- public class ExceptionDemo4 {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- Demo4 d = new Demo4();
- try{
- int x = d.div(4, -1);
- }
- catch(FuShuException e){
- System.out.println(e.toString());
-
- }
- finally{
- System.out.println("finally");//finally中存在的是一定会被执行的代码。
- }
- System.out.println("ocer");
- }
- }
- 在eclipse中报错:
- finally
- Exception in thread "main" java.lang.NoSuchMethodError: Exception.FuShuException: method <init>(Ljava/lang/String;)V not found
- at Exception.Demo4.div(ExceptionDemo4.java:11)
- at Exception.ExceptionDemo4.main(ExceptionDemo4.java:24)
复制代码
正确的不是应该是
FuShuException:除数为负数
finally
over
哪位大神给说说?
|
|