Skip to content

Instantly share code, notes, and snippets.

@punmechanic
Created August 30, 2014 16:35
Show Gist options
  • Save punmechanic/d4836ee7758374448fc3 to your computer and use it in GitHub Desktop.
Save punmechanic/d4836ee7758374448fc3 to your computer and use it in GitHub Desktop.
On a scale of 1 to Game of Thrones spoilers, how evil is this Java code?
/**
* A handler specifically for LwjglExceptions.
* This should be injected via Ioc into a LwjglWindow.
*
* Any instance of an exception occuring in Lwjgl should cause the enclosing program to fail.
* @author Dan
*
*/
class LwjglExceptionHandler implements ExceptionHandler {
private final Logger logger;
private final SystemShutdownStrategy systemShutdownStrategy;
/**
* @param logger - The logger to log messages to. We log to the TRACE level.
* @param systemShutdownStrategy - The strategy to use should we need to shut the system down.
*/
@Inject
public LwjglExceptionHandler(Logger logger, SystemShutdownStrategy systemShutdownStrategy) {
this.logger = logger;
this.systemShutdownStrategy = systemShutdownStrategy;
}
@Override
public void onException(Exception exception) {
logger.trace("lwjgl encountered an error", exception);
systemShutdownStrategy.shutdown();
}
}
@punmechanic
Copy link
Author

Reasoning being behind this is that Lwjgl throws unchecked exceptions on certain methods that obviously do not work with ExecutorService.submit(). As a compromise, I decided that I would catch the exception in ExecutorService.submit() and instead of swallowing the exception, I would pass it to an instance of ExceptionHandler.. and here's the implementation of ExceptionHandler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment