Sebastian Dusza
Sebastian Dusza

Reputation: 2528

Can exception/error in one thread halt the whole application?

If an error / exeption is thrown in a thread (not a main one) can this halt the whole application ?

Is there such possibility ? Or will this just stop the thread it was running in ?

Upvotes: 5

Views: 2279

Answers (2)

Victor Sorokin
Victor Sorokin

Reputation: 11996

In addition to Peter Lawrey's answer, there's one more case when unhandled exception can cause application freeze: if died thread had grabbed some lock needed by other threads of program.

Upvotes: 2

Peter Lawrey
Peter Lawrey

Reputation: 533520

If an error / exeption is thrown in a thread (not a main one) can this halt the whole application ?

It will if it causes the only non-daemon thread to return from run()

If there are other non-daemon threads running or the exception or error is caught and handled, the application will keep running.

will this just stop the thread it was running in ?

if the exception or error is caught and handled it might not stop any threads.

Upvotes: 4

Related Questions