package com.onaro.util.jfc;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* Handles an exception thrown in the AWT event-dispatch thread.
* By default exceptions are just logged.
* AWT's java.awt.EventDispatchThread
searches the system property
* "sun.awt.exception.handler" when it catces an exception. If found it
* will attempt to do the following:public void handle
method,
* which should take a single argument of type Throwable
, and
* handle
method, passing it the thrown
* exception that was caught.
*
* Note: This method is a temporary hack to work around the absence of a * real API that provides the ability to replace the event-dispatch thread. * The magic "sun.awt.exception.handler" property will be removed in a future * release. */ public class AWTExceptionHandler { static Logger logger = LogManager.getLogger(AWTExceptionHandler.class); /** * Handle an uncaught exception by simply sending it to the logger. * * @param t the uncaught exception */ public void handle (Throwable t) { logger.error("Uncaught exception in java.awt.EventDispatchThread - " + t.getMessage(), t); //$NON-NLS-1$ } /** * Install this handler by setting the system property. */ public static void install() { install(AWTExceptionHandler.class.getName()); } /** * Install this handler by setting the system property. * @param className the name of the handler class */ public static void install(String className) { logger.debug("Replacing current AWT exception handler (" + //$NON-NLS-1$ System.getProperty("sun.awt.exception.handler") + //$NON-NLS-1$ ") with " + className); //$NON-NLS-1$ System.setProperty("sun.awt.exception.handler", className); //$NON-NLS-1$ } }