You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AjdeErrorHandler.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* *******************************************************************
  2. * Copyright (c) 1999-2001 Xerox Corporation,
  3. * 2002 Palo Alto Research Center, Incorporated (PARC).
  4. * All rights reserved.
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Public License v1.0
  7. * which accompanies this distribution and is available at
  8. * http://www.eclipse.org/legal/epl-v10.html
  9. *
  10. * Contributors:
  11. * Xerox/PARC initial implementation
  12. * ******************************************************************/
  13. package org.aspectj.ajde.ui.swing;
  14. import java.io.PrintWriter;
  15. import java.io.StringWriter;
  16. import javax.swing.JOptionPane;
  17. import org.aspectj.ajde.Ajde;
  18. import org.aspectj.ajde.ErrorHandler;
  19. public class AjdeErrorHandler implements ErrorHandler {
  20. public void handleWarning(String message) {
  21. JOptionPane.showMessageDialog(AjdeUIManager.getDefault().getRootFrame(),
  22. message,
  23. "AJDE Warning",
  24. JOptionPane.WARNING_MESSAGE);
  25. }
  26. public void handleError(String errorMessage) {
  27. handleError(errorMessage, null);
  28. }
  29. public void handleError(String message, Throwable t) {
  30. String stack = getStackTraceAsString(t);
  31. Ajde.getDefault().logEvent("Error: " + stack);
  32. ErrorDialog errorDialog = new ErrorDialog(AjdeUIManager.getDefault().getRootFrame(), "AJDE Error", t, message, stack);
  33. errorDialog.setVisible(true);
  34. }
  35. private String getStackTraceAsString(Throwable t) {
  36. StringWriter stringWriter = new StringWriter();
  37. if (t != null) {
  38. t.printStackTrace(new PrintWriter(stringWriter));
  39. return stringWriter.getBuffer().toString();
  40. } else {
  41. return "<no stack trace available>";
  42. }
  43. }
  44. }