Java Code Examples for java.lang.Thread.UncaughtExceptionHandler#uncaughtException()

The following examples show how to use java.lang.Thread.UncaughtExceptionHandler#uncaughtException() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TopThreadGroup.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void uncaughtException(Thread t, Throwable e) {
    if (!(e instanceof ThreadDeath)) {
        UncaughtExceptionHandler h = Thread.getDefaultUncaughtExceptionHandler();
        if (h != null) {
            h.uncaughtException(t, e);
            return;
        }
        
        if (e instanceof VirtualMachineError) {
            // Try as hard as possible to get a stack trace from e.g. StackOverflowError
            e.printStackTrace();
        }
        System.err.flush();
        Exceptions.printStackTrace(e);
    }
    else {
        super.uncaughtException(t, e);
    }
}
 
Example 2
Source File: AbstractListFilter.java    From pumpernickel with MIT License 6 votes vote down vote up
/**
 * Fire all ChangeListeners.
 * <p>
 * This should be called when the filter has fundamentally changed what
 * it may accept. For example: if this filter is based on text in a text field,
 * then every time that text field is changed we should call this method
 */
public void fireChangeListeners() {
	for (ChangeListener changeListener : changeListeners
			.toArray(new ChangeListener[changeListeners.size()])) {
		try {
			changeListener.stateChanged(new ChangeEvent(this));
		} catch (Exception e) {
			UncaughtExceptionHandler u = getUncaughtExceptionHandler();
			if (u != null) {
				u.uncaughtException(Thread.currentThread(), e);
			} else {
				e.printStackTrace();
			}
		}
	}
}
 
Example 3
Source File: Application.java    From Augendiagnose with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Define custom ExceptionHandler which takes action on OutOfMemoryError.
 */
private void setExceptionHandler() {
	final UncaughtExceptionHandler defaultExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();

	UncaughtExceptionHandler customExceptionHandler =
			new UncaughtExceptionHandler() {
				@Override
				public void uncaughtException(final Thread thread, final Throwable ex) {
					if (ex instanceof OutOfMemoryError) {
						// Store info about OutOfMemoryError
						PreferenceUtil.setSharedPreferenceBoolean(R.string.key_internal_outofmemoryerror, true);
					}

					// re-throw critical exception further to the os
					defaultExceptionHandler.uncaughtException(thread, ex);
				}
			};

	Thread.setDefaultUncaughtExceptionHandler(customExceptionHandler);
}
 
Example 4
Source File: DefaultRunLoop.java    From firebase-admin-java with Apache License 2.0 5 votes vote down vote up
private void handleExceptionInternal(Throwable e) {
  UncaughtExceptionHandler exceptionHandler;
  exceptionHandler = getExceptionHandler();
  try {
    if (exceptionHandler != null) {
      exceptionHandler.uncaughtException(Thread.currentThread(), e);
    }
  } finally {
    handleException(e);
  }
}
 
Example 5
Source File: ThreadPoolEventTarget.java    From firebase-admin-java with Apache License 2.0 5 votes vote down vote up
@Override
public void uncaughtException(Thread t, Throwable e) {
  try {
    UncaughtExceptionHandler delegate;
    synchronized (this) {
      delegate = exceptionHandler;
    }
    if (delegate != null) {
      delegate.uncaughtException(t, e);
    }
  } finally {
    logger.error("Event handler threw an exception", e);
  }
}
 
Example 6
Source File: jt.java    From letv with Apache License 2.0 5 votes vote down vote up
private void a(Thread thread, Throwable th) {
    for (UncaughtExceptionHandler uncaughtException : c()) {
        try {
            uncaughtException.uncaughtException(thread, th);
        } catch (Throwable th2) {
        }
    }
}
 
Example 7
Source File: ContainerProperties.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * Convert a String representation to an Object
 * 
 * @param toStringValue
 *            the serialized String value
 * @param componentType
 *            the type of object that is returned.
 * @param handler
 *            a handler to notify if something goes wrong
 * @return the Object represented by the argument String.
 */
protected Object convert(String toStringValue, Class<?> componentType,
		UncaughtExceptionHandler handler) {
	if (String.class.equals(componentType))
		return toStringValue;
	if (Boolean.class.equals(componentType)
			|| Boolean.TYPE.equals(componentType))
		return Boolean.parseBoolean(toStringValue);
	if (Integer.class.equals(componentType)
			|| Integer.TYPE.equals(componentType))
		return Integer.parseInt(toStringValue);
	if (Short.class.equals(componentType)
			|| Short.TYPE.equals(componentType))
		return Short.parseShort(toStringValue);
	if (Long.class.equals(componentType) || Long.TYPE.equals(componentType))
		return Long.parseLong(toStringValue);
	if (Character.class.equals(componentType)
			|| Character.TYPE.equals(componentType))
		return toStringValue.charAt(0);
	if (Byte.class.equals(componentType) || Byte.TYPE.equals(componentType))
		return Byte.parseByte(toStringValue);
	if (Float.class.equals(componentType)
			|| Float.TYPE.equals(componentType))
		return Float.parseFloat(toStringValue);
	if (Double.class.equals(componentType)
			|| Double.TYPE.equals(componentType))
		return Double.parseDouble(toStringValue);
	if (BigInteger.class.equals(componentType))
		return new BigInteger(toStringValue);
	if (BigDecimal.class.equals(componentType))
		return new BigDecimal(toStringValue);
	if (File.class.equals(componentType))
		return new File(toStringValue);
	handler.uncaughtException(
			Thread.currentThread(),
			new UnsupportedEncodingException(
					"ContainerProperties cannot parse "
							+ componentType.getCanonicalName()));
	return null;
}
 
Example 8
Source File: ListUncaughtExceptionHandlers.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
@Override
public void uncaughtException(Thread thread, Throwable throwable) {
  synchronized (list) {
    for (UncaughtExceptionHandler handler : list) {
      handler.uncaughtException(thread, throwable);
    }
  }
}
 
Example 9
Source File: RxJavaCommonPlugins.java    From RxJava3-preview with Apache License 2.0 4 votes vote down vote up
static void uncaught(@NonNull Throwable error) {
    Thread currentThread = Thread.currentThread();
    UncaughtExceptionHandler handler = currentThread.getUncaughtExceptionHandler();
    handler.uncaughtException(currentThread, error);
}