Changeset 830


Ignore:
Timestamp:
02/04/14 23:11:35 (10 years ago)
Author:
davidb
Message:

Shutdown handler added to deal with the situation where an Action (a Runnable/Thread) throws an exception.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Actions.java

    r827 r830  
    611611                        _Agent = agent;
    612612
    613                         Thread t = new Thread(_Agent);
     613                        Thread.UncaughtExceptionHandler h = new Thread.UncaughtExceptionHandler() {
     614                            public void uncaughtException(Thread th, Throwable ex) {
     615                         
     616                                MessageBay.errorMessage("Error occurred in Action: " + th.getName());
     617                                ex.printStackTrace();
     618
     619                                stopAgent();
     620                                _Agent = null;
     621                            }
     622                        };
     623                       
     624                        Thread t = new Thread(_Agent,nameWithCorrectCase);
     625               
    614626                        t.setPriority(Thread.MIN_PRIORITY);
    615 
     627                        t.setUncaughtExceptionHandler(h);
     628                       
    616629                        if (FreeItems.textOnlyAttachedToCursor()) {
    617630                                itemParam = FreeItems.getItemAttachedToCursor();
     
    635648                                // background
    636649                                t.run();
    637                                 String result = _Agent.toString();
    638                                 // Attach the result to the cursor
    639                                 if (FreeItems.textOnlyAttachedToCursor()) {
     650                                if (_Agent != null) {
     651                                    String result = _Agent.toString();
     652                                    // Attach the result to the cursor
     653                                    if (FreeItems.textOnlyAttachedToCursor()) {
    640654                                        Item resultItem = FreeItems.getItemAttachedToCursor();
    641655                                        resultItem.setText(result);
     656                                    }
     657                                    // if there is a completion frame, then display it to the user
    642658                                }
    643                                 // if there is a completion frame, then display it to the user
    644659                        } else {
    645660                                t.start();
    646                                 if (_Agent.hasResultFrame()) {
     661                                if (_Agent != null && _Agent.hasResultFrame()) {
    647662                                        // TODO We want to be able to navigate through the frames as
    648663                                        // the results are loading
Note: See TracChangeset for help on using the changeset viewer.