首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

answer question,该如何处理

2012-01-03 
answer questionpublicclassMethodException{publicstaticvoidmain(String[]args){try{myMethod()}catch(

answer question
public   class   MethodException   {

       
        public   static   void   main(String[]   args)   {
       
        try{
        myMethod();
        }
        catch(OurMethodException   e)
        {
        e.printStackTrace();
        }
        public   static   void   MyMethod()   throws   OurMethodException
        {
        yourMethod();
        }
        public   static   void   yourMethod()throws   OurMethodException
        {
        hisMethod();
        }
        public   static   void   hisMethod()throws   OurMethodException
        {
        throw   new   OurMethodException();
        }
        }
    class   OurMethodException   extends   Exception
        {
        public   OurMethodException()
        {
        super( "这是我们的例外类 ");
        }
        }
}
错误在哪里?怎么老提示说:
--------------------Configuration:   MethodException   -   JDK   version   <Default>   -   <Default> --------------------
D:\Program   Files\Java\JCreatorV4\MyProjects\MethodException\src\MethodException.java:22:   非法的表达式开始
                public   static   void   MyMethod()   throws   OurMethodException
                ^
D:\Program   Files\Java\JCreatorV4\MyProjects\MethodException\src\MethodException.java:34:   需要   '; '
        }      
        ^
2   错误

Process   completed.


[解决办法]
package com.qunar.common.test;

import com.susing.util.*;
import java.io.StringWriter;
import java.io.PrintWriter;

public class Test {
public static void MyMethod() throws OurMethodException{
yourMethod();
}
public static void yourMethod()throws OurMethodException{
hisMethod();
}
public static void hisMethod()throws OurMethodException{
throw new OurMethodException();
}

public static void main(String[] args){
try{
MyMethod();
}
catch(OurMethodException e)
{
e.printStackTrace();
}

}

static class OurMethodException extends Exception{
public OurMethodException(){
super( "这是我们的例外类 ");
}
}
}


你的方法定义到方法里面了,还有就是静态的问题

热点排行