debugging multiThreads in intellij: how can i see the all thrown exceptions?

Answered

I have a multithreaded code in java.

I debug with intellij. I know how to switch debug contexts between threads.

Nevertheless the console shows only exception thrown for the main thread.

How can i see the exceptions thrown from any thread?




0
6 comments

Can you share a sample project to illustrate the problem? This may be related to your logging configuration or exception handling inside the application rather than IDE.

In some cases you may need to set up the unhandled exceptions handler for your threads: http://stackoverflow.com/questions/6546193/how-to-catch-an-exception-from-a-thread. Did you do that?

0

It's a bit hard because the exception is thrown in a nested code.

 

basically when I run integration test with an Executor, some exception is thrown from secondary thread. 

But nothing is printed to the debug-console.

 

Actually the the code flies and never reach to the try catch i have.

It's like I cannot step-next after the code that throws an exception


try {
while (true) {
logger.debug("New thread. polling on DB, polling on deployment service");

ConfigAction configAction = configActionFactory.get(ConfigActionsEnum.PushToDeployment);

while (configAction != null) {
configAction = configAction.execute() ? configAction.nextActivity() : null;
}
}
} catch (Exception e) {
e.printStackTrace();
logger.error("DeploymentContextListener run failed", e);
}

whereas when I run with the main thread, the **same** code I see the exception:

 

    public void run() {

try {
while (true) {
logger.debug("New thread. polling on DB, polling on deployment service");

ConfigAction configAction = configActionFactory.get(ConfigActionsEnum.PushToDeployment);

while (configAction != null) {
configAction = configAction.execute() ? configAction.nextActivity() : null;
}
}
} catch (Exception e) {
e.printStackTrace();
logger.error("DeploymentContextListener run failed", e);
}


 

it is written in one of the try-catch i have

 

} catch (Exception ex) {
logger.error("failed to get from DB: getLatestConfigVersionWaitingForDeploy", ex);
}
0

Hi, please provide some more details:

- you set a breakpoint in a code which definitely works, but it is not hit?

- debugger should not affect your console output, unless you do some extra debugger logging, do you?

- please try to set an Exception breakpoint as suggested before and see if it works where expected

0

-it does hi the inner breakpoint, but "step next" finished my test without stepping to next code line.

-I use logging with "system.out". It seems the code never reaches there unless I remove the "threads executor".

-I will try, but even now there is a different behavior for the debugger if I use one-thread or threads executor.

 

0

another idea is to use suspend thread breakpoints (not suspend all), it is switched in breakpoint properties

0
 

My problem was that i used:

 ExecutorService executor = Executors.newSingleThreadExecutor();
        executor.submit(() -> { }

from what I have read:

invokeAll - call “future.get()”. Wait for all threads to finish.

Submit -> attach the errors to Future objects, not the the std-error

Execute -> the errors are thrown to the std-error

1

Please sign in to leave a comment.