Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » How to handle Status and inform enduser of failure
How to handle Status and inform enduser of failure [message #906813] Sun, 02 September 2012 16:55
Mikael Petterson is currently offline Mikael PettersonFriend
Messages: 156
Registered: July 2009
Senior Member

I have some code that executes a command and returns exit code and errorMessage ( if execution fails). The code that makes this call is the following (simplified):

public Status twoWayMerge(String file1, String file2) {
		String [] errMsg = null;
		String[] command = new String[] { getExec(), file1, file2 };
		CommandLauncher launcher = new CommandLauncher();
		launcher.execute(command, null, null, null);
		//Check if command was ok.
		if(launcher.getExitValue() != 0){
			errMsg = launcher.getErrorOutput();
			if(errMsg == null){
				return new Status(IStatus.ERROR, "Plugin id here", "An unknown error occurred!");
				StringBuffer sb = new StringBuffer();
				for (int i = 0; i < errMsg.length; i++) {
				return new Status(IStatus.ERROR, "Plugin id here",sb.toString());
		//everything was ok!
		return new Status(IStatus.OK, "Plugin id here", "Merge was ok");

Since it is a long running Job I use the following to make the call.

public void execute() throws TeamException{
		// execute
		Job job = new Job("Merge") {
			protected IStatus run(IProgressMonitor monitor) {
				IStatus status = null;
				monitor.beginTask("Merge started...", 10);
				// Run long running task here
				// Add a factory here that can decide which launcher to use.
				AbstractDifference merge = MergeFactory.getMergeTool(ClearCasePreferences.getExtMergeTool());
				String vExtPath1 = resource.getLocation().toOSString()+"@@"+comparableVersion;
				String path = resource.getLocation().toOSString();//Dont use version extended path. Since view selects current version.
				if(base == null){
					status = merge.twoWayMerge(file1, file2);
					status = merge.threeWayMerge(file1, file2, path);
					//Throw exception
					throw new TeamException(status);
				return status;

Then I need to provide the user with a message if I have a failure of the command. I use the following code:

		ExternalMergeOperation extMergeOp = new ExternalMergeOperation(resource, comparableVersion, base);
		try {
		} catch (TeamException te) {
			ErrorDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "External Merge title", te.getMessage(), te.getStatus());

Is this the recommend way to do it or is there an easier way to do it? Is there anything I can improve in code? I would be very happy if you give your opinion.


Previous Topic:Autocorrect - the apple way
Next Topic:Please stop adding features.
Goto Forum:

Current Time: Wed Sep 23 04:43:44 GMT 2020

Powered by FUDForum. Page generated in 0.01746 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top