THX
分析并指出下面程序的错误
(提示:有三处简单的语法错误)
public class  Test3
{
public static void main(String[] args)
{
try
{
myMethod();
}catch(MyException e)
{
System.out.println(e.toString());
}
}
public static void myMethod() throw MyException
{
throws(new MyException());
}
}
class MyException 
{
public String toString()
{
return("用户自定义的异常");
}
};

解决方案 »

  1.   

    public class Test3
    {
    public static void main(String[] args)
    {
    try
    {
    myMethod();
    }catch(MyException e)
    {
    System.out.println(e.toString());
    }
    }
    public static void myMethod() throw MyException//throws
    {
    throws(new MyException());//throw new MyException();
    }
    }
    class MyException
    {
    public String toString()
    {
    return("用户自定义的异常");
    }
    };//no ;
      

  2.   

    public class  Test3
    {
        public static void main(String[] args)
        {
            try
            {
                myMethod();
            }catch(MyException e)
            {
                System.out.println(e.toString());
            }
        }
        public static void myMethod() throws MyException
        {
            throw(new MyException());
        }
    }
    class MyException extends Exception
    {
        public String toString()
        {
            return("用户自定义的异常");
        }
    }
      

  3.   

    public class  Test3
    {
    public static void main(String[] args)
    {
    try
    {
    myMethod();
    }catch(MyException e)
    {
    System.out.println(e.toString());
    }
    }
    public static void myMethod() throws MyException    //1
    {
    throw new MyException();                   //2
    }
    }
    class MyException extends Exception                           //3
    {
    public String toString()
    {
    return("用户自定义的异常");
    }
    }                                                              //4
      

  4.   

    class MyException 要继承Exception.
      

  5.   

    1,2 throws<-->throwMyException extends Exception