• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception handling  RSS feed

 
Adrien Ruffie
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I have found the following system:

static class StreamExceptionHandler implements Thread.UncaughtExceptionHandler {
public void uncaughtException(final Thread t, final Throwable e) {
this.handle(e);
}

public void handle(final Throwable throwable) {
throwable.printStackTrace(EXCEPTIONSTREAM_ABSORBER_STREAM);
}
}

This Thread.UncaughtExceptionHandler allow to handle an exception for one thread will be terminated,
but it's don't matche my needs.

I need a mechanism which can allow to catch properly all exceptions throws by one thread, process, runtime ...
in order to redirect the stream where these exceptions are written.

For example catch all exception in order to don't print in user console but more in a log file.

Any one have an idea ? Thank
 
Wouter Oet
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exceptions are per thread. So what you can do is use a ThreadFactory to create threads and set the UnCaughtExceptionHandler to your implementation.
 
Adrien Ruffie
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't because thread, process, runtime ... are already created, when I have the hands on its ..., so impossible to use ThreadFactory because thread instance building was already done
 
Aditya Jha
Ranch Hand
Posts: 227
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Still, if you even have access to all the threads, you can set a single instance of uncaught-exception-handler to each of them. It is not necessarily done at the time of creation of a thread.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!