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("堆栈空。");
}
}
------解决方案--------------------
+1