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( "这是我们的例外类 ");
}
}
}
你的方法定义到方法里面了,还有就是静态的问题