answer question

nanjingxinxi 2007-08-03 06:40:39
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.
...全文
208 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
duckyaya 2007-08-03
  • 打赏
  • 举报
回复
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("这是我们的例外类");
}
}
}


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

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧