Created
August 30, 2014 16:35
-
-
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?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 inExecutorService.submit()
and instead of swallowing the exception, I would pass it to an instance ofExceptionHandler
.. and here's the implementation ofExceptionHandler