KExceptionManager: print stack trace for unhandled exceptions only once. Msg improvement.
@@ -11,7 +11,6 @@ import org.kframework.utils.errorsystem.KException.ExceptionType;
import org.kframework.utils.errorsystem.KException.KExceptionGroup;
import org.kframework.utils.inject.RequestScoped;
-import java.lang.Thread.UncaughtExceptionHandler;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -29,19 +28,14 @@ public class KExceptionManager {
}
public void installForUncaughtExceptions() {
- Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
-
- @Override
- public void uncaughtException(Thread t, Throwable e) {
- if (options.debug) {
- e.printStackTrace();
+ Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
+ String message = "Uncaught exception thrown of type " + e.getClass().getSimpleName();
+ if (!options.debug) {
+ message += ".\nPlease rerun your program with the --debug flag to generate a stack trace, "
+ + "and file a bug report at https://github.com/kframework/k/issues";
}
- exceptions.add(new KException(ExceptionType.ERROR, KExceptionGroup.INTERNAL,
- "Uncaught exception thrown of type " + e.getClass().getSimpleName()
- + ".\nPlease rerun your program with the --debug flag to generate a stack trace, "
- + "and file a bug report at https://github.com/kframework/k/issues", e));
+ exceptions.add(new KException(ExceptionType.ERROR, KExceptionGroup.INTERNAL, message, e));
print();
- }
});
}
