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("用户自定义的异常");
}
};
分析并指出下面程序的错误
(提示:有三处简单的语法错误)
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("用户自定义的异常");
}
};
{
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 ;
{
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("用户自定义的异常");
}
}
{
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