Java 试着不要被强迫

Java 试着不要被强迫,java,eclipse,exception,exception-handling,try-catch,Java,Eclipse,Exception,Exception Handling,Try Catch,我有一个例外: public class ErrorException extends Exception { private static final long serialVersionUID = 1L; private String errorMessage = ""; private int errorCode = 0; private String errorLevel = ""; private Window errorSource = null; public String g

我有一个例外:

public class ErrorException extends Exception
{
private static final long serialVersionUID = 1L;

private String errorMessage = "";
private int errorCode = 0;
private String errorLevel = "";
private Window errorSource = null;

public String getErrorMessage()
{
    return errorMessage;
}

public int getErrorCode()
{
    return errorCode;
}

public String getErrorLevel()
{
    return errorLevel;
}

public Window getErrorSource()
{
    return errorSource;
}

public ErrorException(String message, int code, int level, Window source)
{
    super();

    errorMessage = message;
    errorCode = code;

    switch (level)
    {
        case 0:
        {
            errorLevel = "benignError";
        }

        case 1:
        {
            errorLevel = "criticalError";
        }

        case 2:
        {
            errorLevel = "terminalError";
        }
    }

    errorSource = source;
}
}
我有这个方法:

public static Element check(final Document document) throws ErrorException
{
    try
                        {
                            chapter.resetLatch();

                            final SecondaryLoop loop = Toolkit.getDefaultToolkit().getSystemEventQueue().createSecondaryLoop();

                            new Thread()
                            {
                                @Override
                                public void run()
                                {
                                    SwingUtilities.invokeLater(new Runnable()
                                    {                               
                                        @Override
                                        public void run()
                                        {
                                            answer.getPreviousElement().takeFocus();
                                            question.removeAnswer(answer);
                                            question.rewriteLetters();
                                            Utils.update(chapter);
                                            loop.exit();
                                        }       
                                    });
                                }
                            }.start();

                            loop.enter();

                            chapter.getLatch().await();
                        }

                        catch (InterruptedException e)
                        {
                            throw new ErrorException("blankElementDialogError", 8, 1, Main.getGui().getMasterWindow());
                        }

return new Element();
}
我在这个构造函数代码中使用它:

public ConfirmCloseDialog(final Document document, final int postOperation)
{
    final CustomJButton doSave = new CustomJButton(Main.getString("doSave"), false);
    doSave.addActionListener(new ActionListener()
    {
        @Override
        public void actionPerformed(ActionEvent arg0)
        {   
            getConfirmCloseDialog().dispose();

            new Thread()
            {
                @Override
                public void run()
                {       
/*this method is the one above -->*/Element problem = BlankElementDialog.check(document);

                        if (problem == null)
                        {
                            new SaveChooser(document, postOperation);                   
                        }

                        else
                        {
                            new BlankElementDialog(problem);
                        }
                }
            }.start();  
        }   
    });
 }
第二部分的代码不完整,但在代码的其余部分中没有特殊的构造(只构造了一些GUi对象,构造函数中没有try-catch)

然而,Eclipse并没有强迫我将方法调用封装到try-catch块中,尽管该方法抛出了一个异常(ErorException子类异常)。 我知道异常是检查异常,所以它应该强制它,对吗

为什么?


我该怎么做才能使其生效呢?

即使没有Eclipse应该通知的任何细节,请看以下内容:

只要重新启动Eclipse就可以解决这个问题



显示
ErrorException
的声明。我现在添加了实际引发异常的代码。@Karlovsky120您只发布了ErrorException构造函数-您可以发布ErrorException类声明吗?好的,现在就这样。似乎Eclipse应该让您捕获它。你可以尝试的一件事是清理和重建项目。我已经重新启动了它,但没有任何更改。它仍然没有看到它。只是重新启动了它,这次它起了作用。它一定与清除和重建项目有关。@Karlovsky120-看,你的代码并不比我的简单,所以Eclipse应该提醒你。如果不是,我想这不是关于java,而是关于Eclipse(可能是安装问题)。
public class TestClass {
    public static void main(String[] args) {
        method(2);//Notification here!
    }
    static void method(int a) throws myException {
    }
}
class myException extends Exception {

}