/** * Copies the stack trace of the exception passed in parameter, and sets the port which caused the exception. * * @param e the exception we need to copy the stack trace from. * @param port the selected port which was the cause of the exception. */ public AbstractPortException(Exception e, int port) { setStackTrace(e.getStackTrace()); this.port = port; }
public InvalidPortException(Exception e) { setStackTrace(e.getStackTrace()); } }
public InvalidHostException(UnknownHostException e, String host) { setStackTrace(e.getStackTrace()); this.host = host; }
ThreadPoolExecutor exec = new ThreadPoolExecutor...; exec.setThreadFactory(new ExceptionCatchingThreadFactory(exec.getThreadFactory())); //go on to submit tasks... private static class ExceptionCatchingThreadFactory implements ThreadFactory { private final ThreadFactory delegate; private ExceptionCatchingThreadFactory(ThreadFactory delegate) { this.delegate = delegate; } public Thread newThread(final Runnable r) { Thread t = delegate.newThread(r); t.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { e.printStackTrace(); //replace with your handling logic. } }); return t; } }
/** * Switches the text inside the button and calls the PortTextField observer to enable/disable the port field. * * @see PortTextField */ public void toggleButton() { try { UIModel.INSTANCE.toggleButton(); } catch (InvalidHostException ihe) { displayError(String.format(i18n.get("startsrv.err.invalidHost"), ihe.getHost())); } catch (InvalidPortException ipe) { displayError(String.format(i18n.get("startsrv.err.invalidPort"))); } catch (BindPortException bpe) { displayError(String.format(i18n.get("startsrv.err.bound"), bpe.getPort())); } catch (OutOfRangePortException orpe) { displayError(String.format(i18n.get("startsrv.err.range"), orpe.getPort())); } catch (RuntimeException re) { displayError(String.format(i18n.get("startsrv.err.default"), re.getMessage())); } if (UIModel.INSTANCE.isStarted()) { button.setText(i18n.get("startsrv.started")); button.setEnabled(false); } setChanged(); notifyObservers(); }
public MyBroadcastReceiver() { final UncaughtExceptionHandler defaultUEH = Thread .getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable ex) { // TODO Handle Exception defaultUEH.uncaughtException(thread, ex); } }); }
throw new InvalidPortException(e); } catch (UnknownHostException e) { throw new InvalidHostException(e, hostStr);
/** * Starts the server on the port and address specified in parameters. * * @param port the SMTP port to be opened. * @param bindAddress the address to bind to. null means bind to all. * @throws BindPortException when the port can't be opened. * @throws OutOfRangePortException when port is out of range. * @throws IllegalArgumentException when port is out of range. */ public void startServer(int port, InetAddress bindAddress) throws BindPortException, OutOfRangePortException { LOGGER.debug("Starting server on port {}", port); try { smtpServer.setBindAddress(bindAddress); smtpServer.setPort(port); smtpServer.start(); } catch (RuntimeException exception) { if (exception.getMessage().contains("BindException")) { // Can't open port LOGGER.error("{}. Port {}", exception.getMessage(), port); throw new BindPortException(exception, port); } else if (exception.getMessage().contains("out of range")) { // Port out of range LOGGER.error("Port {} out of range.", port); throw new OutOfRangePortException(exception, port); } else { // Unknown error LOGGER.error("", exception); throw exception; } } }
/** * Called when an uncaught exception is thrown. Will display the error message in a dialog box. * * @param t the thread where the exception was throws. * @param e the thrown exception. */ @Override public void uncaughtException(final Thread t, final Throwable e) { try { if (SwingUtilities.isEventDispatchThread()) { showException(t, e); } else { SwingUtilities.invokeLater(new Runnable() { public void run() { showException(t, e); } }); } } catch (Exception excpt) { LOGGER.error("", excpt); } }
((UncaughtExceptionHandler) Thread.getDefaultUncaughtExceptionHandler()).setParentComponent(panel.get()); Dimension frameSize = new Dimension(Integer.parseInt(Configuration.INSTANCE.get("application.min.width")), Integer.parseInt(Configuration.INSTANCE.get("application.min.height")));
GWT.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { public void onUncaughtException(Throwable e) { // TODO Global Exception Handling ... } });
Thread.currentThread().setUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable ex) { ...
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler());
public class ForceClose extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler(this)); setContentView(R.layout.main); // Your mechanism is ready now.. In this activity from anywhere if you get force close error it will be redirected to the CrashActivity. }}
UncaughtExceptionHandler uncaughtExceptionHandler = new UncaughtExceptionHandler(){ @Override public void uncaughtException(Thread thread, Throwable ex) { //Here print the log... } }; Thread.setDefaultUncaughtExceptionHandler(uncaughtExceptionHandler);
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable ex) { // your code } });
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { public void uncaughtException(Thread thread, Throwable ex) { // log, or create some statistics ... whatever } });
setContentView(R.layout.current); Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { android.os.Process.killProcess(android.os.Process.myPid()); System.exit(0); } code....
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread t, Throwable e) { // TODO implement this } });
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable ex) { // TODO Auto-generated method stub } });