this is my main method:
public static void main(String... args) throws ClassNotFoundException {
String[] classAndMethod = args[0].split("#");
if (helpCmd(args)) {
printHelpForTest(classAndMethod[1]);
System.exit(0);
}
Result result = runTest(classAndMethod);
exitIfTimeOutExceptionThrown(result);
System.exit(result.wasSuccessful() ? 0 : 1);
}
private static void exitIfTimeOutExceptionThrown(Result result) {
boolean isTimeOut = Iterables.filter(result.getFailures(), CodeBlockTimeOutException.class).iterator().hasNext();
if (isTimeOut)
{
System.exit(2);
}
}
which runs this junit test:
@Test
public void sendSearchRequest() throws Exception {
...
setTimeOut();
...
}
private void setTimeOut() {
if (criticalBlockTimeOut != null) {
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
throw new CodeBlockTimeOutException();
//thread.interrupt();
}
};
new Timer().schedule(timerTask, Long.parseLong(criticalBlockTimeOut));
}
}
why i see my code throws the CodeBlockTimeOutException
but it main never exit with code 2?
how can I throw it to be caught in the main thread?