Question

I have this Exception:

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;
}
}

And I have this method:

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();
}

And I use it in this constructor code:

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();  
        }   
    });
 }

The code for the second part is not full, but there are no special constructs in the rest of the code (just some GUi objects being constructed and there is no try catch anywhere in the constructor).

However, Eclipse isn't forcing me to encapsulate the method call into try catch block, despite the fact that the method throws an Exception (ErorrException subclasses Exception). And I know that Exception is checked exception, so it should force it, right?

Why?

What do I have to do so it would force it?

Was it helpful?

Solution

Even without any details Eclipse should notify, look at this:

enter image description here

Just restart the Eclipse should solve the issue.


public class TestClass {
    public static void main(String[] args) {
        method(2);//Notification here!
    }
    static void method(int a) throws myException {
    }
}
class myException extends Exception {

}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top