读书人

自定义两个错误为什么这样有错到底

发布时间: 2013-11-05 14:40:42 作者: rapoo

自定义两个异常,为什么这样有错,到底错哪了,求大神指导
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

读书人网 >Java相关

热点推荐