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.

BrowserErrorHandler.java 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /********************************************************************
  2. * Copyright (c) 2007 Contributors. All rights reserved.
  3. * This program and the accompanying materials are made available
  4. * under the terms of the Eclipse Public License v 2.0
  5. * which accompanies this distribution and is available at
  6. * https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
  7. *
  8. * Contributors: IBM Corporation - initial API and implementation
  9. * Helen Hawkins - initial version (bug 148190)
  10. *******************************************************************/
  11. package org.aspectj.tools.ajbrowser.core;
  12. import java.io.PrintWriter;
  13. import java.io.StringWriter;
  14. import javax.swing.JOptionPane;
  15. import org.aspectj.ajde.Ajde;
  16. import org.aspectj.ajde.ui.swing.ErrorDialog;
  17. import org.aspectj.tools.ajbrowser.BrowserManager;
  18. /**
  19. * Error handler used by AjBrowser. Handles errors and warnings by
  20. * producing an error/warning dialog.
  21. */
  22. public class BrowserErrorHandler {
  23. public static void handleWarning(String message) {
  24. JOptionPane.showMessageDialog(BrowserManager.getDefault()
  25. .getRootFrame(), message, "AJBrowser Warning",
  26. JOptionPane.WARNING_MESSAGE);
  27. }
  28. public static void handleError(String errorMessage) {
  29. handleError(errorMessage, null);
  30. }
  31. public static void handleError(String message, Throwable t) {
  32. String stack = getStackTraceAsString(t);
  33. ErrorDialog errorDialog = new ErrorDialog(Ajde.getDefault()
  34. .getRootFrame(), "AJBrowser Error", t, message, stack);
  35. errorDialog.setVisible(true);
  36. }
  37. private static String getStackTraceAsString(Throwable t) {
  38. StringWriter stringWriter = new StringWriter();
  39. if (t != null) {
  40. t.printStackTrace(new PrintWriter(stringWriter));
  41. return stringWriter.getBuffer().toString();
  42. }
  43. return "<no stack trace available>";
  44. }
  45. }