The programme continues to work after a rough exception



  • I have this class:

    private class MyThread extends SwingWorker<Void, Void> {
        private MultidimensionalSolver solver;
    
    @Override
    protected Void doInBackground() throws Exception {
        manager.getInfoPanel().setVisible(true);
        solver = new MultidimensionalSolver(manager.getTask());
        while (!solver.isSolutionFind() &amp;&amp; flag) {
            solver.findSolution();
            manager.getTask().setSolution(
                    solver.getSolution().getSolution());
        }
        return null;
    }
    
    public void done() {
        //setSolution();
        throw new NullPointerException();
    }
    
    private void setSolution() {
        manager.getInfoLabel().setText(solver.getSolution().toGuiString());
        if (!manager.getTable().isTableSoluted()) {
            manager.getTable().addLastColumn();
            manager.getRowTable().addSolutionRow();
        }
        manager.getRowTable().updateUi();
    }
    

    }

    I had an exception in the setSolution. Which was more obvious, I'm generating an exception in the method. There's a very strange behavior going on. I'm not processing an exception anywhere. Swing worker I'm starting here:

    private void callSolver() {
    manager.getStop().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            flag = false;
        }
    });
    thread = new MyThread();
    thread.execute();
    

    }

    This method is called:

    @Override
    protected void createOkAction() {
    if (withEdit.isSelected()) {
    manager.getTask().setSolutionEditable(true);
    } else {
    manager.getTask().setSolutionEditable(false);
    }
    callSolver();
    }

    And he's here in turn:

    protected JButton createOkButton(){
    JButton ok = new JButton("ok");
    ok.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            createOkAction();
            frame.dispose();
        }
    });
    return ok;
    

    }

    I mean, it's a button processor.
    As you can see, I don't do anything about the exception. But after that exception, there's stacktrace going on and the program doesn't fall! I can keep working with the GUI, like I've never been. Why would such behaviour happen? I suspect it might have something to do with adding SwingWorker's program to a multi-point program.



  • public class NullPointerException extends RuntimeException
    

    This exception is uncheckedif it occurs in another flow and if it is not processed, it will be used http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.UncaughtExceptionHandler.html It's a default that'll just lead stack trace. Flow performance will be interrupted.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2