日期:2014-05-20  浏览次数:20654 次

自定义两个异常,为什么这样有错,到底错哪了,求大神指导
class EmptyStackException extends Exception 
{
public EmptyStackException(String message) 

super(message);
}
}
class FullStackException extends Exception 
{
public FullStackException(String message) 

super(message);
}
}
public class UserdefinedException
{
public static void main(String[] args)  
{
try 
{
throw new EmptyStackException("堆栈空。");
throw new FullStackException("堆栈满。");

catch (EmptyStackException e)  
{
System.out.println("异常信息是:\n" + e.toString());
}
catch (FullStackException e)  
{
System.out.println("异常信息是:\n" + e.toString());
}
}
}
java 报错

------解决方案--------------------
class EmptyStackException extends Exception {
public EmptyStackException(String message) {
super(message);
}
}

class FullStackException extends Exception {
public FullStackException(String message) {
super(message);
}
}

public class UserdefinedException {
public static void main(String[] args) throws Exception{
throw new EmptyStackException("堆栈空。");
}
}

------解决方案--------------------
引用:
class EmptyStackException extends Exception {
public EmptyStackException(String message) {
super(message);
}
}

class FullStackException extends Exception {
public FullStackException(String message) {
super(message);
}
}

public class UserdefinedException {
public static void main(String[] args) throws Exception{
throw new EmptyStackException("堆栈空。");
}
}

+1