如何解决错误“未处理的异常类型异常”

时间:2020-10-07 02:00:51

标签: java driver

控制台向我显示消息:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Unhandled exception type Exception
package driver;

import exception.StackException;
import stack.*;

public class StackDriver 
{

    public static void main(String[] args) 
    {
        StackInterface<Painting> painting = new LinkedStack <Painting>();
        
        System.out.println("Creating five paintings.");
        Painting A = new Painting("Rembrandt" , "Netherlands" , "Dutch Golden Age");
        Painting B = new Painting("Leonardo da Vinci", "Italy" , "Renaissance");
        Painting C = new Painting("Michelangelo", "Italy" , "Renaissance");


        painting.push(A);
        painting.push(B);
        painting.push(C);
        
        try 
        {
//Below is the line that is giving me this error. Specially painting.peek();

            System.out.println("Peeking at top of painting stack." + painting.peek());
            
            
        }catch (StackException e) 
        {
            System.out.println(e);
        }
        
    }
}

// This is my exception package with the StackException class.

package exception;

public class StackException extends RuntimeException
{

    public StackException()
    {
        super("The stack is empty.");
    }
    public StackException(String msg) {
        super (msg);
    }
}

0 个答案:

没有答案