Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2000, 2007 IBM Corporation, BEA Systems, Inc., and others All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html Contributors: wharley@bea.com - based on org.eclipse.jdt.internal.ui.util.ExceptionHandler /
 
 
 package org.eclipse.jdt.apt.ui.internal.util;
 
 
 import  org.eclipse.core.runtime.CoreException;
 import  org.eclipse.core.runtime.IStatus;
 import  org.eclipse.core.runtime.Status;
 import  org.eclipse.swt.widgets.Shell;

This code is The default exception handler shows an error dialog when one of its handle methods is called. If the passed exception is a CoreException an error dialog pops up showing the exception's status information. For a InvocationTargetException a normal message dialog pops up showing the exception's message. Additionally the exception is written to the platform log.
 
 public class ExceptionHandler {
 
 	private static ExceptionHandler fgInstancenew ExceptionHandler();

Logs the given exception using the platform's logging mechanism. The exception is logged as an error with the error code AptUIPlugin.INTERNAL_ERROR.
 
 	public static void log(Throwable tString message) {
 		AptUIPlugin.log(new Status(IStatus.ERROR.
 			.messaget));
 	}

Handles the given CoreException. The workbench shell is used as a parent for the dialog window.

Parameters:
e the CoreException to be handled
title the dialog window's window title
message message to be displayed by the dialog window
 
 	public static void handle(CoreException eString titleString message) {
 		handle(e, AptUIPlugin.getActiveWorkbenchShell(), titlemessage);
 	}

Handles the given CoreException.

Parameters:
e the CoreException to be handled
parent the dialog window's parent shell
title the dialog window's window title
message message to be displayed by the dialog window
 
 	public static void handle(CoreException e, Shell parentString titleString message) {
 		.perform(eparenttitlemessage);
 	}

Handles the given InvocationTargetException. The workbench shell is used as a parent for the dialog window.

Parameters:
e the InvocationTargetException to be handled
title the dialog window's window title
message message to be displayed by the dialog window
 
 	public static void handle(InvocationTargetException eString titleString message) {
 		handle(e, AptUIPlugin.getActiveWorkbenchShell(), titlemessage);
 	}

Handles the given InvocationTargetException.

Parameters:
e the InvocationTargetException to be handled
parent the dialog window's parent shell
title the dialog window's window title
message message to be displayed by the dialog window
 
 	public static void handle(InvocationTargetException e, Shell parentString titleString message) {
 		.perform(eparenttitlemessage);
 	}
 
 	//---- Hooks for subclasses to control exception handling ------------------------------------
 	
 	protected void perform(CoreException e, Shell shellString titleString message) {
 		AptUIPlugin.log(e);
 		IStatus statuse.getStatus();
 		if (status != null) {
			ErrorDialog.openError(shelltitlemessagestatus);
else {
			displayMessageDialog(ee.getMessage(), shelltitlemessage);
		}
	}
	protected void perform(InvocationTargetException e, Shell shellString titleString message) {
		if (target instanceof CoreException) {
			perform((CoreException)targetshelltitlemessage);
else {
			AptUIPlugin.log(e);
			if (e.getMessage() != null && e.getMessage().length() > 0) {
				displayMessageDialog(ee.getMessage(), shelltitlemessage);
else {
				displayMessageDialog(etarget.getMessage(), shelltitlemessage);
			}
		}
	}
	//---- Helper methods -----------------------------------------------------------------------
	private void displayMessageDialog(Throwable tString exceptionMessage, Shell shellString titleString message) {
		if (message != null) {
			msg.write(message);
			msg.write("\n\n"); //$NON-NLS-1$
		}
		if (exceptionMessage == null || exceptionMessage.length() == 0)
		else
			msg.write(exceptionMessage);
		MessageDialog.openError(shelltitlemsg.toString());			
	}	
New to GrepCode? Check out our FAQ X