Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse StatusManager do not show detail

Code:

Job job = new Job("Connect to Database") { 
            @Override 
            protected IStatus run(IProgressMonitor monitor) {
                // 即使是在正常的情况下,某些版本的DB2的连接建立时间也比较长。。。
                monitor.beginTask("正在建立到数据库的连接 ...", 100); 
                try {
                    Thread.sleep(3000);
                    database = new Database(cp.getName(),  cp.getConnection());
                } catch (Exception e) {
                    e.printStackTrace();
                    IStatus sqlErrorStatus = new Status(IStatus.ERROR, "amarsoft.dbmp", e.getMessage(), null);
                    StatusManager.getManager().handle(sqlErrorStatus, StatusManager.SHOW);
                }
                monitor.done(); 
                return Status.OK_STATUS; 
            } 
        }; 

enter image description here

How can I make it display the exception's stack trace when user click the 'Details' button?

like image 827
CaiNiaoCoder Avatar asked Mar 13 '12 12:03

CaiNiaoCoder


1 Answers

Default details area of status dialog does not display exception stack trace.

If you have your own Eclipse product then you can customize details and support areas of the status dialog using org.eclipse.ui.statusHandlers extension point. You will need to extend WorkbenchErrorHandler and override configureStatusDialog(...) method:

void configureStatusDialog(WorkbenchStatusDialogManager statusDialog) {
    statusDialog.enableDefaultSupportArea(true);
    statusDialog.setDetailsAreaProvider(new CustomStatusAreaProvider());
}

class CustomStatusAreaProvider extends AbstractStatusAreaProvider {
    Control createSupportArea(Composite parent, StatusAdapter statusAdapter) {
        //Create and return details area
    }
}



By passing the exception to Status instead of null you make the stack trace available for details dialog of error log view.

like image 78
Martti Käärik Avatar answered Sep 22 '22 15:09

Martti Käärik