当前位置: 代码迷 >> Java相关 >> 自定义两个错误,为什么这样有错,到底哪里错了,求大神指导
  详细解决方案

自定义两个错误,为什么这样有错,到底哪里错了,求大神指导

热度:127   发布时间:2016-04-22 21:31:50.0
自定义两个异常,为什么这样有错,到底错哪了,求大神指导
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
  相关解决方案